【发布时间】:2015-03-26 22:16:44
【问题描述】:
我正在使用 MAMP 服务器来托管 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);
?>
【问题讨论】:
-
我错过了
the code given by PHPMyAdmin -
在mysql_query()之后尝试
print mysql_error();; (更好......if (!mysql_query(...)) { print mysql_error(); } else { print "updated"; })