我最近从mysql转移到mysqli,现在尝试将我的代码重新格式化为mysqli。
请指导我这些陈述的错误。
代码:
<?php
include_once 'dbconnect.php';
$sample ='sample123'; // these are dummy values
$orecip='admin'; // these are dummy values
$omessage='test'; // these are dummy values
$date = date('Y-m-d'); // these are dummy values
$read='yes'; // these are dummy values
$read1='no'; // these are dummy values
$otitle='test'; // these are dummy values
$insert = $MySQLi_CON->query("INSERT INTO messages (user_from, user_to, title, message, date, user_from_read, user_to_read)
VALUES($sample, $orecip, $otitle ,$omessage,$date,$read,$read1)");
print '<h3>Insert Multiple records</h3>';
if($insert){
//return total inserted records using mysqli_affected_rows
print 'Success! Total ' .$MySQLi_CON->affected_rows .' rows added.<br />';
}else{
die('Error : ('. $MySQLi_CON->errno .') '. $MySQLi_CON->error);
}
?>
错误:
错误:(1054)“字段列表”
中的未知列'sample123'
答案 0 :(得分:0)
你在VALUES部分忘记了引用,它应该是这样的:
$MySQLi_CON->query("INSERT INTO messages (user_from, user_to, title, message, date, user_from_read, user_to_read)
VALUES('$sample', '$orecip', '$otitle' ,'$omessage','$date','$read','$read1')");