我看不出我的脚本有什么问题,我不明白为什么它不能插入到我创建的数据库中。请看我的代码,并建议什么可能是错误的。这是用于所有数据库连接的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";
}
?>发布于 2013-10-21 18:08:21
// ...
$c = mysql_connect($host,$user,$password) or die(mysql_error());
// ...
mysql_query($sql, $c);发布于 2013-10-21 18:08:54
$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";
}https://stackoverflow.com/questions/19491465
复制相似问题