Been hustling with this for a while but cant still get the page to reload after deleted a row.
The row removing is working fine, but it only appears after I reload the page.
Been moving around some of the code to get it read when pressing submit but no luck.
Any Ideas ?
<?php
mysql_connect("localhost", "root", "") or die(mysql_error()) ;
mysql_select_db("booking") or die(mysql_error()) ;
$resultselect = mysql_query("SELECT * FROM test_mysql ") or die(mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>row delete</title>
<link rel="stylesheet" type="text/css" href="" />
</head>
<body>
<?php
if(isset($_POST['done'])){
$done = implode(',', $_POST['done']);
$deletequery = "DELETE FROM test_mysql WHERE id IN ($done)";
$resultdelete = mysql_query($deletequery) or die(mysql_error());
}
?>
<form method="post" action="">
<?php while($row = mysql_fetch_array($resultselect)){?>
<input type="checkbox" name="done[]"
id="<?php echo $row['id'] ?>"
value="<?php echo $row['id'] ?>">
<label for="<?php echo $row['id'] ?>">
<?php echo $row['name'] . ' ' . $row['lastname']. ' '.$row['email']; ?>
</label>
<br />
<?php } ?>
<input type ="submit" value ="submit">
</form>
<?php
if($resultdelete) {
echo 'Item(s) deleted from list.';
}
?>
<pre>
<?php print_r($_POST) ?>
</pre>
</body>
</html>
I’m assuming since the code you have provided is a snippet of your application code that
$resultselectis set someplace before this part gets executed.The important part here is the order of your MySQL queries. If you are
SELECTing rows before youDELETErows, then you will still see deleted rows when you runmysql_fetch_array()Move the
SELECTquery after theDELETEquery and all should be fine.