<?php
mysql_connect("10.246.16.129", "alanay_org", "SNIP")or die("Cannot Connect");
mysql_select_db("alanay_org")or die("cannot select DB");
INSERT INTO members ('id', 'username', 'password')
VALUES
(NULL, '$_POST[username]','$_POST[password]')";
?>
我的代码没有插入我的MySQL表,行按id,用户名和密码。我已经检查过,并且我从HTML注册表单中找不到任何错误。请帮忙。
抱歉,我是PHP的新手。给我一个休息时间。
编辑:
这是register.php
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<link rel="stylesheet" type="text/css" href="/form/stylesheet.css" />
</head>
<body>
<center>
<form action="/form/registered.php" method="post">
<input class="username" name="username" type="text" placeholder="Username" />
<input class="password" name="password" type="password" placeholder="Password" />
<input class="submit" type="submit" value="Register" />
</form>
</center>
</body>
</html>
这是registered.php
<?php
$con = mysqli_connect("10.246.16.129","alanay_org","password","alanay_org");
$sql = "INSERT INTO members ('username', 'password') VALUES ('$_POST['username']','$_POST['password']')";
mysqli_query($con, $sql);
?>
我做错了什么? :(
答案 0 :(得分:2)
您的帖子变量语法错误。这样:
$_POST[username]
应该是:
$_POST['username']
再加上@Dagon说的话。
答案 1 :(得分:0)
以下是如何操作:
$con=mysqli_connect("host","username","password","database_name");
mysqli_query($con,"INSERT INTO members ('username', 'password') VALUES ($_POST['username'], $_POST['password']);
如果是自动递增,则不需要输入id SQL方法不能保证此方法的安全性。出于安全目的,您可以使用预准备语句。
答案 2 :(得分:0)
<?php
mysql_connect("10.246.16.129", "alanay_org", "SNIP")or die("Cannot Connect");
mysql_select_db("alanay_org")or die("cannot select DB");
mysql_query("INSERT INTO members ('username', 'password') VALUES ('".$_POST['username']."','".$_POST['password']."')");
?>
如果这对您不起作用,则您的POST变量将丢失或为空。