首页 > PHP批量删除提示unexpected 'foreach' (T_FOREACH)

PHP批量删除提示unexpected 'foreach' (T_FOREACH)

<?php
$con = mysql_connect("localhost",'root','123456') or die('error:'.mysql_error());
mysql_select_db('student',$con) or die('error:'.mysql_error());
mysql_query('set NAMES utf8');
$id=$_POST['id']; 
if(is_array($id) && !empty($id)){
    foreach($id as $ide){ 
    $exec="delete from mysearch where Id=".$ide; 
    $result=mysql_query($exec); 
        } 
}
mysql_close(); 
Header("search_index.php");
?>

错误提示为:PHP Parse error: syntax error, unexpected 'foreach' (T_FOREACH) in I:\php-moive\search_delall.php on line 7
百度“ unexpected 'foreach' (T_FOREACH)”几乎找不到相关答案。。


<?php

$id=$_POST['id']; 
if(is_array($id) && !empty($id)){
   $ids = implode(',',$id);
   $exec="delete from mysearch where Id in($ids)"; 
   $result=mysql_query($exec); 
}

语法应该没错,错在括号。还有那个$id是数组的话,拼接字符串,直接delete from mysearch where Id in 字符串.不用再遍历执行多条sql语句了。


你用的中文的括号

if(is_array($id) && !empty($id)){

if(is_array($id) && !empty($id)){   <--  这个大括号打成全角了

unexpected xxx 一般是报错的内容前面有语法错误。

【热门文章】
【热门文章】