$sql="SELECT retail_peak, number from callplandata ";
$rs=mysql_query($sql,$conn);
$sql2='';
while($result=mysql_fetch_array($rs)) {
    $sql2.="UPDATE callplandata set ".$_POST["callplancopy_newname"]." = '".$result[$_POST["callplancopy"]]."' where number = '".$result["number"]."'; ";
}
$rs2=mysql_query($sql2,$conn) or die(mysql_error());


我正在尝试运行上述查询,我​​在最后将$sql2设置为;,所以我只运行一个查询,而不是许多单独的查询。

我收到此错误消息:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UPDATE callplandata set dcabr = '0' where number = '44*116'; UPDATE callplandata' at line 1


当我回显$sql2时,它看起来像-http://www.wepaste.com/sql2/

最佳答案

不建议使用mysql,但它也不允许在单个查询中使用多个语句。

但是,您可以使用mysqli_multi_query在mysqli的单个查询中使用多个语句

关于php - while循环内的PHP单个查询未在MySQL上运行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25143724/

10-10 10:55
查看更多