为什么这个mySQL PHP代码不起作用?

时间:2017-12-24 18:44:39

标签: php mysql

[注意编辑:这个问题是不同的,因为我要求表格数据不会转移/插入我的SQL数据库]

我有一个网站,你可以登录/注册我已经创建了一个phpAdmin / mySQL数据库,其中有一个表来保存数据。我用HTML编写了一个表单:



<br>
<br>
<text align="center">
<div id="body-context">
<h3>You can't login to accounts yet, but you can create one here!</h3>
<p>You will be able to login to accounts in 2.5 days</p>
<p>
<form action="create-account.php" method="post">
<input type="text" placeholder="Username, 8-16 characters" name="username" pattern=".{8,16}" required>
<br>
<input type="password" placeholder="Password, 9-26 characters" name="password" pattern=".{9,26}" required>
<br>
<input type="text" placeholder="Email Address" name="email" pattern=".{11,}" required>
<br>
<input type="submit" value="Create Account">
</form>
</p>
</div>
</text>
&#13;
&#13;
&#13;

PHP :(这是create-account.php操作页面)

&#13;
&#13;
<?php

con = mysqli_connect('server-name', 'username', 'password', 'database-name')

	if(!$con)
	{
		echo 'Not Connected to Server';
	}

if(!mysqli_select_db($con, 'database-name'))
{
	echo 'Database Not Selected';
}

$username = $POST['username'];
$password = $POST['password'];
$email = $POST['email'];

$sql = "INSERT INTO Users (username,email,password) VALUES ('$username','$email','$password')";

if(!mysqli_query($con,$sql))
{
	echo 'Not Inserted';
}
else
{
	echo 'Inserted';
}

?>
&#13;
&#13;
&#13;

我在我正在进行的网站上测试了代码,但在我填写表单并提交之后,我去查看数据库,没有任何内容。我一直在努力,但没有什么在那里。我该如何解决这个问题(或者如果出现问题就调试代码)?

1 个答案:

答案 0 :(得分:-3)

所有这些:

$username = $POST['username'];
$password = $POST['password'];
$email = $POST['email'];

更改为以下内容:

$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];

$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$email = $_REQUEST['email'];