0

我的脚本没有任何问题,我不明白为什么它不会插入到我创建的数据库中。请查看我的代码并告知可能出现的问题。这是用于所有数据库连接的 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";
}

?>
4

2 回答 2

0
// ...
$c = mysql_connect($host,$user,$password) or die(mysql_error()); 
// ...
mysql_query($sql, $c);
于 2013-10-21T10:08:21.153 回答
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";
}

另见:http ://www.php.net/manual/en/mysqli.query.php

于 2013-10-21T10:08:54.470 回答