我创建了一个注册表单,您可以在其中提交您的详细信息,并将它们保存在数据库中。我有一个名为“标题”的字段之一的下拉框,并且未提交此数据。我希望我能得到一些关于这个问题的反馈,也许可以解决这个问题。
<!DOCTTYPE html>
<head><link rel="stylesheet" type="text/css" href="style/style.css"></head>
<title>Registration</title>
<body>
<form name="form1" method="post" action="register_ac.php">
<li>Title<select name="title" id="title"><option value="MR">MR</option><option value="MRS">MRS</option></option><option value="MISS">MISS</option></select></li>
<li>FirstName<input type="text" name="firstname" class="#" id="firstname"/></li>
<li>Surname<input type="text" name="surname" class="#" id="surname"/></li>
<li>Username<input type="text" name="username" class="#" id="username"/></li>
<li>Password<input type="password" name="password" class="#" iid="password"/></li>
<li>Email<input type="text" name="email" class="#" id="email"/></li>
<li>Addressline1<input type="text" name="addressline1" class="#" id="addressline1"/></li>
<li>Addressline2<input type="text" name="addressline2" class="#" id="addressline2"/></li>
<li>City<input type="text" name="city" class="#" id="city"/></li>
<li>County<input type="text" name="county" class="#" id="county"/></li>
<li>Postcode<input type="text" name="postcode" class="#" id="postcode"/></li>
<input type="submit" id="textarea" name="submit" value="Submit" class="button"/>
</form>
</body>
</html>
<?php
$host="localhost"; // Host name
$username="#####"; // Mysql username
$password="#####"; // Mysql password
$db_name="#####"; // Database name
$tbl_name="Register"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Get values from form
$username=$_POST['username'];
$title=$_POST['title'];
$firstname=$_POST['firstname'];
$surname=$_POST['surname'];
$password=$_POST['password'];
$email=$_POST['email'];
$addressline1=$_POST['addressline1'];
$addressline2=$_POST['addressline2'];
$city=$_POST['city'];
$county=$_POST['county'];
$postcode=$_POST['postcode'];
// Insert data into mysql
$sql="INSERT INTO $tbl_name(username, title, firstname, surname, password, email, addressline1, addressline2, city, county, postcode)
VALUES('$username', '$title', '$firstname','$surname','$password','$email','$addressline1','$addressline2','$city','$county','$postcode')";
$result=mysql_query($sql);
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='index.php'>Back to main page</a>";
}
else {
echo "ERROR";
}
?>
<?php
// close connection
mysql_close();
?>