我使用MAMP Server托管MySQL数据库来存储有关用户帐户的一些信息。
当我尝试使用PHPMyAdmin提供的代码插入条目时,它不会插入它。有人可以告诉我我的代码有什么问题吗?
<?php
$username = "username";
$password = "*******";
$hostname = "localhost:8889";
$inputUsername = $_POST["username"];
$inputPassword = $_POST["password"];
$confirmPassword = $_POST["confirmPassword"];
if ($inputPassword != $confirmPassword) {
die("Your two password entries are not the same!");
}
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
$sql = mysql_select_db("billet",$dbhandle)
or die("Could not select database");
$sql = mysql_query("INSERT INTO `billet` (`username`, `password' VALUES ('$inputUsername', '$inputPassword')");
echo "Inserted values! <a href='index.html'>Go</a>";
mysql_close($dbhandle);
?>
答案 0 :(得分:0)
您需要查询数据库以插入所需的数据,目前您只是连接到数据库然后关闭。
你需要做这样的事情(取决于你的MySQL表):
$result = mysql_query("INSERT INTO `billet` (`username`, `password`) VALUES ('$inputUsername', '$inputPassword')");
您还应该考虑切换到PDO,因为mysql_
函数已被弃用。