Php 当我想查询保存多行MySQL数据库时,我遇到了一个错误

Php 当我想查询保存多行MySQL数据库时,我遇到了一个错误,php,mysql,Php,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 l

我越来越犯这样的错误

"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());}
}
if($form_finished){
//已删除数据库信息以在此处发布。
$link=mysql_connect('******'、'***'、'*****');
如果(!$link){die('无法连接:'.mysql_error());}
mysql_select_db(“清单”);
$query=“”;
$spcats=爆炸(“,”,$fat_cats);
$query.=“插入到列表中”;

对于($k=0;$k如果要使用单个INSERT语句插入多个值,则只需指定values关键字一次,因此这些行

$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.=“插入列表”;

对于($k=0;$k),在查询结束时挂起
可能会导致issues@jprofitt:$query=substr($query,0,strlen($query)-1)。”;此代码也是最后删除的。但是,如果我将生成的相同代码复制到phpmyadmin中并按下查询按钮,则所有数据都保存到表中。并且生成的相同代码在我的代码的查询过程中不起作用。@jprofitt是的,我认为,但是OP正在删除查询,最好将所有插入存储在一个数组中,然后内爆它们。@extremerose71您是否尝试过在脚本失败时通过回显查询来调试脚本?
$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 .= "INSERT INTO listings VALUES "; 

 for($k=0;$k<count($spcats)-1;$k++){
    $query .= " (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."'),"; 
}