php - Warning Invalid argument supplied for foreach() -
i getting error message , don't have clue it.
warning: invalid argument supplied foreach() in /home/a9083956/public_html/zundappgroesbeek/beheer/testretrievesql.html on line 31
this code working with. warning 31st line, foreach()
line. ive changed =
=>
make checkbox work, delete code won't work still.
<html> <head> <title>retrieve , delete data database </title> </head> <body> <?php // connect 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 * forum_question"; // execute query (the recordset $rs contains result) $rs = mysql_query($strsql); // loop recordset $rs // each row made array ($row) using mysql_fetch_array while($row = mysql_fetch_array($rs)) { // write value of column firstname (which in array $row) echo '<input name="delete['.$row['id'].']" type="checkbox">'; echo $row['topic']. " " .$row['name']. " " .$row['datetime'] . "<br />"; $delete = $_post['delete']; foreach($delete $id => $value) { $id = mysql_real_escape_string($id); mysql_query("delete table_name id => $id"); } } // close database connection mysql_close(); ?> </body> </html>
if don't check boxes, $_post['delete']
not set. use if (isset($_post['delete']))
before foreach
.
also there's bug in sql, want where id = "$id"
, otherwise delete more rows intended...
Comments
Post a Comment