2014-04-10 3 views
0

==>으로 변경했습니다.사용자가 mysql 행을 삭제할 수있게하려고했습니다

Warning: Invalid argument supplied for foreach() in /home/a9083956/public_html/zundappgroesbeek/beheer/testretrievesql.html on line 31


내가 PHP를 오류 메시지가 무엇입니까 : 불행하게도, 난 다른 오류 메시지가 표시됩니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

Parse error: syntax error, unexpected '=', expecting ')' in /home/a9083956/public_html/zundappgroesbeek/beheer/testretrievesql.html on line 31

내 HTML은 다음과 같습니다

<html> 
    <head> 
    <title>Retrieve data from database </title> 
    </head> 
    <body> 

    <?php 
    // Connect to database server 
    mysql_connect("mysql7.000webhost.com", "a9083956_test", "sesam") or die (mysql_error()); 

    // Select database 
    mysql_select_db("a9083956_test") or die(mysql_error()); 

    // SQL query 
    $strSQL = "SELECT * FROM forum_question"; 

    // Execute the query (the recordset $rs contains the result) 
    $rs = mysql_query($strSQL); 

    // Loop the recordset $rs 
    // Each row will be made into an array ($row) using mysql_fetch_array 
    while($row = mysql_fetch_array($rs)) { 

     // Write the value of the column FirstName (which is now in the array $row) 
      echo '<input name="delete['.$row['id'].']" type="checkbox">'; 
     echo $row['topic']. " " .$row['name']. " " .$row['datetime'] . "<br />"; 
     } 

$delete = $_POST['delete']; 

foreach($delete as $id = $value) 
{ 
    $id = mysql_real_escape_string($id); 
    mysql_query("DELETE FROM table_name WHERE id = $id"); 
} 

// Close the database connection 
mysql_close(); 
?> 
</body> 
</html> 
+0

가능한 [양식 삭제 버튼으로 PHP를 사용하여 MySQL 데이터베이스에서 행을 삭제하는 방법] (http://stackoverflow.com/questions/23425147/how-to-deleterows-from-a-mysql- 데이터베이스 사용 - PHP와 - 양식 - 삭제 버튼) – Unihedron

답변

0

귀하의 문제는 당신이 $id = $value이있는 foreach 루프에 자리 잡고 있습니다. 나는 당신이 의미 의심 :

foreach($delete as $id => $value) 
{ 
    $id = mysql_real_escape_string($id); 
    mysql_query("DELETE FROM table_name WHERE id = $id"); 
} 

=>=의 변화.

=> 연산자에 대한 자세한 내용은 관련 게시물 here을 참조하십시오.

+0

고마워 내가 많이 변경했지만 지금은 다른 오류 메시지가있어. 경고 :/home/a9083956/public_html/zundappgroesbeek/beheer에서 foreach()에 잘못된 인수가 제공됨 /testretrievesql.html on line 31 –

관련 문제