我已经创建了 php、form 和 mysql 数据库。密码可以使用表单很好地写入数据库,但用户名不会。我已经为此困扰了好几个小时(这可能是一个非常简单的解决方法,有人可以提供见解吗?谢谢!
<?php
echo "connected ";
//get form data
if( !isset( $user ) ) {
$user = strtolower( mysql_real_escape_string( $_POST['user'] ) );
}
if( !isset( $user ) ) {
$pass = md5( mysql_real_escape_string( $_POST['password'] ) );
}
//connect to MySQL
$connect = mysql_connect( $dbhost, $dbuser, $dbpass )
or die ("connection error");
echo "connected ";
//select databse
mysql_select_db( $dbdb ) or die ("database selection error");
//insert data
$insert = mysql_query("INSERT INTO androidlogin (user, pass) VALUES ('$user','$pass')");
if( $insert ) {
$arr2 = array("user" => $user, "pass" => $pass);
echo json_encode( $arr2 );
}
?>
<html>
<head>
</head>
<body>
<title>PHP Register</title>
<form action="registerBBD.php" method="POST">
User: <input type="text" name="user" id="user" /><br />
Pass: <input type="text" name="pass" id="pass" /><br />
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>