Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
207 views
in Technique[技术] by (71.8m points)

How to fix syntax error in PHP "unexpected ')'"

I Have got Error in the Foreach loop in below Code,Can any one Help me to Fix the Error...

<form method="post" action="<?php  echo $_SERVER['PHP_SELF'];?>">

<?php



$dbc=mysqli_connect("localhost","root","","elvis_store") or die("Error Connecting to Mysql Database");

if(isset($_POST['submit'])){

foreach($_POST['todelete'] as delete_id){

$query="DELETE FROM email_list WHERE id=$delete_id";
mysqli_query($dbc,$query) or die("Error Querying Database");

}

echo "Customer(s) Removed";


}



$query="SELECT * FROM email_list";
$result=mysqli_query($dbc,$query)or die("Query Syntaxt is Incorrect");

while($row=mysqli_fetch_array($result)){

echo '<input type="checkbox" value="'.$row['id'].'" name="todelete[]"/>';
echo $row['first_name']." ".$row['last_name']." ".$row['email'];
echo "<br/>";




}



mysqli_close($dbc);




?>

<input type="submit" name"submit" value="Remove"/>




</body>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think the error must be due to this line:

foreach($_POST['todelete'] as delete_id){

Replace it with:

foreach($_POST['todelete'] as $delete_id){

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...