2013-07-26 62 views
1

我無法在數據庫中獲得INSERT查詢。我沒有收到任何錯誤消息,並且正在關注教程,任何幫助都將不勝感激。插入不插入任何錯誤消息的查詢

$query = "INSERT INTO rooms (room_title,room_description,monthly_rate,prop_name,prop_description) VALUES (?, ?, ?, ?, ?)"; 

$stmt = mysqli_prepare($dbc,$query); 
//$stmt = mysqli_query($dbc, $query); 
if($stmt == false) { 
    die("<pre>".mysqli_error($dbc).PHP_EOL.$query."</pre>"); 
} 

mysqli_stmt_bind_param($stmt,"ssiss",$pn,$d,$p,$ppn,$ppd); 
mysqli_stmt_execute($stmt); 
//mysqli_stmt_close($stmt); 
// Check the results... 
if (mysqli_stmt_affected_rows($stmt) == 1) 

    { 

    echo'<p>The room has been added.</p>';     
    // Clear $_POST: 
    $_POST = array(); 

    } 

mysqli_stmt_close($stmt); 

} // End of $errors IF. 
// End of the submission IF. 

因爲它沒有回聲「房間已經加入」我懷疑問題是與mysqli_stmt_affected_rows($stmt) == 1

+2

檢查mysqli_stmt_execute – Orangepill

+0

的回報。如果'mysqli_stmt_execute'回報假,調用'mysqli_error()'得到錯誤信息。 – Barmar

回答

0

試試這個

if ($stmt = mysqli_prepare($dbc, "INSERT INTO rooms (room_title,room_description,monthly_rate,prop_name,prop_description) VALUES (?, ?, ?, ?, ?)")) { 

mysqli_stmt_bind_param("ssiss",$pn,$d,$p,$ppn,$ppd); 

mysqli_stmt_execute($stmt); 

} printf("Error: %s.\n", mysqli_stmt_error($stmt));