的多行我得到前來錯誤,如我收到錯誤,當我想查詢保存MySQL數據庫
"Could not connect: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES (null, '206', 'asdas', 'asasdff', 'asdfasd', 'asdsdsad', 'asdasdf', 'qw' at line 1"
代碼是在這裏:
if($form_finished){
// database info removed for posting here.
$link = mysql_connect('******', '****', '*****');
if (!$link) {die('Could not connect: ' . mysql_error());}
mysql_select_db('listing');
$query="";
$spcats = explode(",", $fat_cats);
$query .= "INSERT INTO listings ";
for($k=0;$k<count($spcats)-1;$k++){
$query .= " VALUES (null, '".$spcats[$k]."', '".$contact_fname."', '".$contact_lname."', '".$contact_email."', '".$contact_phone."', '".$listing_company_name_1."', '".$listing_phone_1."', '".$listing_address_1."', '".$listing_city_1."', '".$listing_state_1."', '".$listing_zip_1."', '".$listing_description_1."', '".$format_listing_urls."', '".$format_perimeters."'),";
}
$query = substr($query, 0, strlen($query)-1) . ";";
$result=mysql_query($query);
if (!$result) {die('Could not connect: ' . mysql_error());}
}
但是當我使用簡單的查詢,我將被保存在數據庫中。
從另一種方式,我做了一些變化做了:
for($k=0;$k<count($spcats)-1;$k++){
$query = "INSERT INTO listings VALUES (null, '".$spcats[$k]."', '".$contact_fname."', '".$contact_lname."', '".$contact_email."', '".$contact_phone."', '".$listing_company_name_1."', '".$listing_phone_1."', '".$listing_address_1."', '".$listing_city_1."', '".$listing_state_1."', '".$listing_zip_1."', '".$listing_description_1."', '".$format_listing_urls."', '".$format_perimeters."');";
$result=mysql_query($query);
if (!$result) {die('Could not connect: ' . mysql_error());} else {print $spcats[$k]." is done.<br>";}
}
做一個var_dum查詢的p。 –