-1

我创建了一个注册表单,您可以在其中提交您的详细信息,并将它们保存在数据库中。我有一个名为“标题”的字段之一的下拉框,并且未提交此数据。我希望我能得到一些关于这个问题的反馈,也许可以解决这个问题。

 <!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();
?>
4

3 回答 3

4

您在这一行有一个错误:

<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>

一个太多的</option>标签。尝试:

<li>Title<select name="title" id="title"><option value="MR">MR</option><option value="MRS">MRS</option><option value="MISS">MISS</option></select></li>
于 2013-01-31T15:20:13.690 回答
3

不确定是否相关,但你</option></option>有。

我在顶部使用诸如此类的东西来调试 POST 数据:

if ( !empty( $_POST ) )
    echo '<pre>' . print_r( $_POST, true ) . '</pre>';

多次使我免于头痛。

于 2013-01-31T15:22:43.283 回答
1

正如 Oldskool 所说,您应该使用准备好的语句(有关信息,请参阅http://php.net/manual/en/mysqli.prepare.php)来执行查询,或者至少转义值。也就是说,你有一个额外的笨拙</option>的东西挂在那里,它可能会让你的浏览器感到困惑。

于 2013-01-31T15:27:27.990 回答