我发现我的脚本没有任何问题,我不明白为什么它不会插入到我创建的数据库中。请仔细看看我的代码并告知可能出错的地方。 这是dbcon.php,它用于所有数据库连接
<?php
$host="localhost";
$user="root";
$password="";
$db="cottonboard";
$tablename="user";
mysql_connect($host,$user,$password) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
?>
现在是将输入插入数据库的脚本,
<?php
include "dbcon.php";
extract($_POST);
/* just to test if all fields will be outputted
print_r($_POST);*/
$sql="INSERT INTO $tablename(id,username,password,accesslevel,sex,contactnmuber,employer)
VALUES('null','$usernameuser','$passworduser','$accesslevel','$gender','$contactnumberuser','$employeruser')" or die(mysql_error());
if($sql)
{
echo"we got here safe";
}
?>
答案 0 :(得分:0)
// ...
$c = mysql_connect($host,$user,$password) or die(mysql_error());
// ...
mysql_query($sql, $c);
答案 1 :(得分:0)
$sql="INSERT INTO $tablename(id,username,password,accesslevel,sex,contactnmuber,employer) VALUES('null','$usernameuser','$passworduser','$accesslevel','$gender','$contactnumberuser','$employeruser')";
$mysqli = new mysqli($host, $user, $password, $db);
if ($mysqli->query($sql) === TRUE) {
echo"we got here safe";
}