另一个问题在这里。我创建了将数据插入数据库。然后,我收到错误通知:未定义索引:第 252 行上的名称.. 这是我的代码.. 下面是表单代码..
<form id="form1" name="form1" method="post" action="<?=$_SERVER['PHP_SELF']?>">
<input type="submit" name="submit" id="submit" value="Submit" />
<input name="reset" type="reset" id="reset" value="Reset" />
<?php
if(!isset($_POST['submit']))
{
//form not submitted
}
else
{
//get from input
//escape input values for greater safety
$name=(trim($_POST['name'])=='')? die ('ERROR : Enter name') : mysql_escape_string($_POST['name']); // line 252
$address=(trim($_POSTname['address'])=='')? die ('ERROR : Enter Address') : mysql_escape_string($_POST['address']);
$phone=(trim($_POST['phone'])=='')? die ('ERROR : Enter Phone') : mysql_escape_string($_POST['phone']);
$email=(trim($_POST['email'])=='')? die ('ERROR : Enter Email') : mysql_escape_string($_POST['contact']);
$item1=(trim($_POST['item1'])=='')? die ('ERROR : Enter Donut') : mysql_escape_string($_POST['item1']);
$item2=(trim($_POST['item2'])=='')? die ('ERROR : Enter Donut') : mysql_escape_string($_POST['item2']);
$item3=(trim($_POST['item3'])=='')? die ('ERROR : Enter Donut') : mysql_escape_string($_POST['item3']);
$item4=(trim($_POST['item4'])=='')? die ('ERROR : Enter Donut') : mysql_escape_string($_POST['item4']);
$item5=(trim($_POST['item5'])=='')? die ('ERROR : Enter Donut') : mysql_escape_string($_POST['item5']);
//open connection
$connection=mysql_connect('localhost', 'root', '') or die ('Unable to connect');
//select database
mysql_select_db('donut') or die ('Unable to select database');
//create query
$query= "INSERT INTO ordering (name,address,phone,email,item1,item2,item3,item4,item5) VALUES ('$name','$address','$phone','$email', '$item1','$item2','$item3','$item4','$item5')";
//execute query
$result=mysql_query($query) or die ("Error in query: $query.".mysql_error());
//print ID of inserted record
echo 'New record has been successfully inserted';
//close connection
mysql_close($connection);
}
?>
</form>
好吧,这是我的表单代码.. 你能看到任何错误吗?
<td width="24%" class="n"><label for="name">Name:</label></td>
<td width="26%"><input type="text" name="name" id="name" /></td>
<td width="50%"> </td>
</tr>
<tr>
<td class="n"><label for="address">Address:</label></td>
<td><textarea name="address" id="address"></textarea></td>
<td> </td>
</tr>
<tr>
<td class="n"><label for="phone">Phone Number :</label></td>
<td><input type="text" name="phone" id="phone" /></td>
<td> </td>
</tr>
<tr>
<td class="n"><label for="email">Email :</label></td>
<td><input type="text" name="email" id="email" /></td>
<td> </td>
</tr>
<tr>
<td class="n"><label for="donut"> Choose Donut :</label></td>
<td><p>
<span class="k">
<select name="item1" id="item1">
<option>Colorful Choc </option>
<option>Black Forest</option>
<option>chezzy Gum</option>
<option>Orange</option>
<option>Coconut Bead</option>
<option>Cheese Gaeden</option>
<option>Creamy Straw</option>
<option>Stripe Donut</option>
<option>Choc Sugar</option>
<option>Chocolate Chip</option>
<option>Pillow Choc</option>
<option>Star Wars</option>
<option>Regular</option>
<option>Diamond Bead</option>
<option>Strawberry</option>
<option>Munchys</option>
<option>Popcorn</option>
<option>Berry Cheese</option>
<option>Sugar Bread</option>
<option>Choc Chopstick</option>
<option>Regular Planta</option>
<option>Round Round</option>
<option>Sprinkle Nuts</option>
<option>Sprinkle Color</option>
</select>
</span></p>
<p>
<span class="k">
<select name="item2" id="item2">
<option>Colorful Choc </option>
<option>Black Forest</option>
<option>chezzy Gum</option>
<option>Orange</option>
<option>Coconut Bead</option>
<option>Cheese Gaeden</option>
<option>Creamy Straw</option>
<option>Stripe Donut</option>
<option>Choc Sugar</option>
<option>Chocolate Chip</option>
<option>Pillow Choc</option>
<option>Star Wars</option>
<option>Regular</option>
<option>Diamond Bead</option>
<option>Strawberry</option>
<option>Munchys</option>
<option>Popcorn</option>
<option>Berry Cheese</option>
<option>Sugar Bread</option>
<option>Choc Chopstick</option>
<option>Regular Planta</option>
<option>Round Round</option>
<option>Sprinkle Nuts</option>
<option>Sprinkle Color</option>
</select>
</span></p>
<p>
<span class="k">
<select name="item3" id="item3">
<option>Colorful Choc </option>
<option>Black Forest</option>
<option>chezzy Gum</option>
<option>Orange</option>
<option>Coconut Bead</option>
<option>Cheese Gaeden</option>
<option>Creamy Straw</option>
<option>Stripe Donut</option>
<option>Choc Sugar</option>
<option>Chocolate Chip</option>
<option>Pillow Choc</option>
<option>Star Wars</option>
<option>Regular</option>
<option>Diamond Bead</option>
<option>Strawberry</option>
<option>Munchys</option>
<option>Popcorn</option>
<option>Berry Cheese</option>
<option>Sugar Bread</option>
<option>Choc Chopstick</option>
<option>Regular Planta</option>
<option>Round Round</option>
<option>Sprinkle Nuts</option>
<option>Sprinkle Color</option>
</select>
</span></p>
<p>
<span class="k">
<select name="item4" id="item4">
<option>Colorful Choc </option>
<option>Black Forest</option>
<option>chezzy Gum</option>
<option>Orange</option>
<option>Coconut Bead</option>
<option>Cheese Gaeden</option>
<option>Creamy Straw</option>
<option>Stripe Donut</option>
<option>Choc Sugar</option>
<option>Chocolate Chip</option>
<option>Pillow Choc</option>
<option>Star Wars</option>
<option>Regular</option>
<option>Diamond Bead</option>
<option>Strawberry</option>
<option>Munchys</option>
<option>Popcorn</option>
<option>Berry Cheese</option>
<option>Sugar Bread</option>
<option>Choc Chopstick</option>
<option>Regular Planta</option>
<option>Round Round</option>
<option>Sprinkle Nuts</option>
<option>Sprinkle Color</option>
</select>
</span></p>
<p>
<span class="k">
<select name="item5" id="item5">
<option>Colorful Choc </option>
<option>Black Forest</option>
<option>chezzy Gum</option>
<option>Orange</option>
<option>Coconut Bead</option>
<option>Cheese Gaeden</option>
<option>Creamy Straw</option>
<option>Stripe Donut</option>
<option>Choc Sugar</option>
<option>Chocolate Chip</option>
<option>Pillow Choc</option>
<option>Star Wars</option>
<option>Regular</option>
<option>Diamond Bead</option>
<option>Strawberry</option>
<option>Munchys</option>
<option>Popcorn</option>
<option>Berry Cheese</option>
<option>Sugar Bread</option>
<option>Choc Chopstick</option>
<option>Regular Planta</option>
<option>Round Round</option>
<option>Sprinkle Nuts</option>
<option>Sprinkle Color</option>
</select>
</span></p></td>
<td><p class="k">T</p></td>
</tr>
<tr>
<td class="n"> </td>
<td> </td>
<td> </td>
</tr>
<tr>