0
以下是我正在處理的php代碼,插入查詢似乎在我將其放入phpMyAdmin時起作用(使用XAMPP),但$狀態由於某種原因在此處運行查詢時返回false ...我嘗試了更改Insert語句和執行文件輸出檢查以查看問題來自何處的每種組合,但是我完全被難住現在。有任何想法嗎?php SQL語句不起作用,但是當我嘗試在DBMS中使用語句時,它們可以工作
function addQuestion($question_to_add) {
global $host, $username, $password, $dbName, $user_table, $registered_user_table, $question_table;
global $answer_table, $user_answer, $user_post;
connectToDB($username, $password, $host, $dbName);
//$countQuery = "SELECT COUNT(QID) FROM questions";
//$count = mysql_fetch_array(mysql_query($countQuery))[0];//we fetch an array of counts for each column and return the count of column 0
$addQuestionQuery = "INSERT INTO questions (QID, UID, title, _timestamp, numRating, content, category, location) VALUES (0, 7, 0, 0, 0, 0, 0, 0)";
$status = mysql_query($addQuestionQuery);
if ($status == false) {// if the query failed, for whatever reason, let us know.
file_put_contents("out","false");
return false;
}
file_put_contents("out","true");
return true;
}
有用:
function connectToDB($user, $password, $server_host, $db_name) {
$conn = mysql_connect($server_host, $user. $password);
if (!$conn) {
die("Could not connect: " . mysql_error());
//
}
mysql_select_db($db_name, $conn);
}
使用['mysql_error'(http://php.net/mysql_error),以獲得用於調試的原因。 – Gumbo 2014-09-20 06:26:10