0

i have this form in html:

<form id="form_269808" class="appnitro"  method="post" action="">
					<div class="form_description">
			<h2>Basic Information</h2>
			<p>Please fill up your information correctly. All fields are required</p>
		</div>						
			<ul >
			
					<li id="li_1" >
		<label class="description" for="element_1">First Name </label>
		<div>
			<input id="element_1" name="element_1" class="element text medium" type="text" maxlength="255" value=""/> 
		</div><p class="guidelines" id="guide_1"><small>Enter your first name</small></p> 
		</li>		<li id="li_2" >
		<label class="description" for="element_2">Last Name </label>
		<div>
			<input id="element_2" name="element_2" class="element text medium" type="text" maxlength="255" value=""/> 
		</div><p class="guidelines" id="guide_2"><small>Enter your last name</small></p> 
		</li>		<li id="li_3" >
		<label class="description" for="element_3">Middle Name </label>
		<div>
			<input id="element_3" name="element_3" class="element text medium" type="text" maxlength="255" value=""/> 
		</div><p class="guidelines" id="guide_3"><small>Enter your middle name</small></p> 
		</li>		<li id="li_5" >
		<label class="description" for="element_5">Address </label>
		<div>
			<input id="element_5" name="element_5" class="element text medium" type="text" maxlength="255" value=""/> 
		</div><p class="guidelines" id="guide_5"><small>Enter your complete address</small></p> 
		</li>		<li id="li_6" >
		<label class="description" for="element_6">Email </label>
		<div>
			<input id="element_6" name="element_6" class="element text medium" type="text" maxlength="255" value=""/> 
		</div><p class="guidelines" id="guide_6"><small>Enter your valid email address</small></p> 
		</li>		<li id="li_8" >
		<label class="description" for="element_8">Major </label>
		<div>
		<select class="element select medium" id="element_8" name="element_8"> 
			<option value="" selected="selected"></option>
<option value="1" >BS Architecture</option>
<option value="2" >BS Computer Engineering</option>
<option value="3" >BS Civil Engineering</option>
<option value="4" >BS Electrical Engineering</option>
<option value="5" >BS Mechanical Engineering</option>

		</select>
		</div><p class="guidelines" id="guide_8"><small>Please choose your enrolled major</small></p> 
		</li>		<li id="li_7" >
		<label class="description" for="element_7">Date of Birth </label>
		<span>
			<input id="element_7_1" name="element_7_1" class="element text" size="2" maxlength="2" value="" type="text"> /
			<label for="element_7_1">MM</label>
		</span>
		<span>
			<input id="element_7_2" name="element_7_2" class="element text" size="2" maxlength="2" value="" type="text"> /
			<label for="element_7_2">DD</label>
		</span>
		<span>
	 		<input id="element_7_3" name="element_7_3" class="element text" size="4" maxlength="4" value="" type="text">
			<label for="element_7_3">YYYY</label>
		</span>
	
		<span id="calendar_7">
			<img id="cal_img_7" class="datepicker" src="calendar.gif" alt="Pick a date.">	
		</span>
		<script type="text/javascript">
			Calendar.setup({
			inputField	 : "element_7_3",
			baseField    : "element_7",
			displayArea  : "calendar_7",
			button		 : "cal_img_7",
			ifFormat	 : "%B %e, %Y",
			onSelect	 : selectDate
			});
		</script>
		<p class="guidelines" id="guide_7"><small>Enter your date of birth</small></p> 
		</li>		<li id="li_9" >
		<label class="description" for="element_9">Gender </label>
		<span>
			<input id="element_9_1" name="element_9" class="element radio" type="radio" value="1" />
<label class="choice" for="element_9_1">Male</label>
<input id="element_9_2" name="element_9" class="element radio" type="radio" value="2" />
<label class="choice" for="element_9_2">Female</label>

		</span><p class="guidelines" id="guide_9"><small>Please select your gender</small></p> 
		</li>
			
					<li class="buttons">
			    <input type="hidden" name="form_id" value="269808" />
			    
				<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
		</li>
			</ul>
		</form>

DATABASE:

id    firstname  lastname   middlename   address  gender  major   date_of_birth
  1     asdfa       dsfd       jhfhf        jjfd      g    hgshfd        1-12-95
...      ...         ...          ...        ...      ...    ...            ...

How do i code in php if i want to compare if the text inputted in the field is the same in all the fields in the information in the database?

Edited by Narue: added code tags

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by cwarn23
0

When posting a form using html there are two methods you may use which will alter the way you will use the php code. Inside the <form> tag you may use <form method="POST"... or <form method="GET"... Upon using them they will correspond with the following php code.

$_GET //method="GET"
$_POST //method="POST"

However to uses these variables or arrays as they are called, you will need to know the name of the fields you used in your form. For example, if you used <form method="POST"><input name="myname"... then you would use $_POST to access what was in the myname field. If however you used method="GET" then you would access it with $_GET and you can place inside the quotes whatever is inside name="" within the form posted. As per how to compare them you can simply use the following:

if ($_POST['some_name']=='value') {
//it has compared successfully.
}
/*or to compare from mysql*/
mysql_connect('localhost','root','');
mysql_select_db('my_database');
mysql_query('SELECT * FROM `table` WHERE `column`="'.mysql_real_escape_string($_POST['thename']).'"') or die(mysql_error());

So those are the basics to it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.