所以,我有一个 .php 文件,用于检查某人的用户名是否可用,然后将其存储在数据库中,“检查”部分起作用,然后将用户重定向到正确的页面,但是,数据不是被存储在数据库中。
它引用的表单来自用户单击以实际启用此 .php 文件的文件。
(我标记了应该将数据存储在 mysql 数据库中的代码部分)
<?php
$host="localhost";
$username="root";
$password="___________";
$db_name="test_database";
$tbl_name="members";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$username=$_POST['username'];
$password=$_POST['password'];
$email=$_POST['email'];
$username = stripslashes($username);
$username = mysql_real_escape_string($username);
$sql="SELECT * FROM $tbl_name WHERE username='$username'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
// If result matched $myusernametable row must be 1 row
if($count==1){
header("location:register_failure.html");
}
else {
$username=$_POST['username'];//Start of code which should store data in database
$password=$_POST['password'];
$email=$_POST['email'];
$sql = "INSERT INTO members (username, password, email) VALUES ('$username',
'$password', '$email')";//End of code which should store data in database
header("location:register_success.html");
}
?>