我在php中有一个函数,允许用户输入信息并将其添加到sql数据库中。当添加更多数据时,似乎总是缺少我的第一个值。最后一个值似乎向下移动,因此那里甚至没有任何值。这是代码:
$firstname = $_POST['Fname'];
$lastname = $_POST['Lname'];
$age = $_POST['age'];
$gender = $_POST['Gender'];
$city = $_POST['city'];
$email = $_POST['email'];
$condition = $_POST ['condition'];
if ($condition == 'add')
{
$SQL = "INSERT INTO People (Last_Name, First_Name, Age, Gender, Email, Cityid)
VALUES ('$lastname', '$firstname', '$age', '$gender', '$email', '$city')";
$result=mysql_query($SQL) or die(mysql_error());
}
这是HTML:
<form action = 'Project 5 Page 2.php' Method = 'POST'>
<center>
First Name <input type = 'text' maxlength = '20' name = 'Fname'>
<br>
Last Name <input type = 'text' maxlength = '20' name = 'Lname'>
<br>
Email <input type = 'text' maxlength = '100' name = 'email'>
<br>
Male <input type = 'radio' name = 'Gender' value = 'Male'>
Female <input type = 'radio' name = 'Gender' value = 'Female'>
<br>
Age <Select name = 'age' value = 'agename'>
<option value = 'agevalue'>Select</option>
<?php
for ($i=0;$i<121;$i++)
{
echo "<option value=".$i.">".$i."</option>";
}
?>
</select>
<br>
<?php
$SQL="SELECT * from cities ORDER BY province ASC";
$result=mysql_query($SQL) or die(mysql_error());
$num_results=mysql_num_rows($result);
mysql_close($db);
?>
City <select name = 'city' value = 'citychoose'>
<option value = 'citychoice'>Select</option>
<?php
for ($c=0;$c<$num_results;$c++)
{
$row=mysql_fetch_array($result);
echo "<option value='".$row['id']."'>".$row['name'].", ".$row['province']." </option>";
}
?>
</select>
<br>
Add <input type = 'radio' name = 'condition' value = 'add'>
Edit <input type = 'radio' name = 'condition' value = 'Edit'>
Delete <input type = 'radio' name = 'condition' value = 'Delete'>
<br>
<input type="submit" value = Submit>