Home > Backend Development > PHP Tutorial > PHP批量删除提示unexpected 'foreach' (T_FOREACH)是什么原因?

PHP批量删除提示unexpected 'foreach' (T_FOREACH)是什么原因?

PHPz
Release: 2020-06-24 09:53:04
Original
3446 people have browsed it

PHP批量删除提示unexpected 'foreach' (T_FOREACH)是什么原因?

使用PHP编写批量删除功能,代码运行报错,提示unexpected 'foreach' (T_FOREACH)

<?php
$con = mysql_connect("localhost",&#39;root&#39;,&#39;123456&#39;) or die(&#39;error:&#39;.mysql_error());
mysql_select_db(&#39;student&#39;,$con) or die(&#39;error:&#39;.mysql_error());
mysql_query(&#39;set NAMES utf8&#39;);
$id=$_POST[&#39;id&#39;]; 
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");
?>
Copy after login

错误提示为:

Parse error:  syntax error, unexpected &#39;foreach&#39; (T_FOREACH) in I:\php-moive\search_delall.php on line 7
Copy after login

百度“ unexpected 'foreach' (T_FOREACH)”几乎找不到相关答案。。

后来发现是因为语法出现错误:

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

Parse error:  syntax error, unexpected xxx 一般是报错的内容前面有语法错误。

语法错误特点

1、程序还没开始运行。

2、程序报的是Parse error错误。

推荐教程:PHP视频教程

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template