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 に答える