Hey guys
I have trouble picking the specific id of an entry i want to delete
so please take a look at the codes first
Here's the function for making the form:
function am_query_display_quick($page,$order ='DATE DESC'){
global $email;
$conn = db_connect_2();
$color1 = "tableRowOdd";
$color2 = "tableRowEven";
$RowCount = 0;
$result = $conn->query("SELECT pro,pro_update,ana,ana_update,cell,cell_update,cellother,cellother_update,gen,gen_update,genother,genother_update,author,author_update,other,other_update,id
FROM mailing_list
WHERE email = '$email'
ORDER BY $order LIMIT $start_row, $max_per_page;");
echo "<form method = \"post\" action=\".{$_SERVER['PHP_SELF']}.\">";
echo "<table class=\"sortable\" id=\"query_quick2\" width=\"100%\" >\r\n";
echo "\t<tr><th></th><th>Promoter
Locus</th><th>Update?</th><th>Anatomical Area</th><th>Update?</th><th>Cell
Type</th><th>Update?</th><th>Other Cell Type</th><th>Update?</th><th>Genetic
Background</th><th>Update?</th><th>Other Gen.
Back.</th><th>Update?</th><th>Author</th><th>Update?</th><th>Other</th><th>Update?</th><th></th>\r\n";
if($result->num_rows){
while ($row = $result->fetch_array()){
$RowCount ++;
$row_color = ($RowCount % 2) ? $color1 : $color2;
echo "\t<tr class=\"$row_color\" ><td><input type=\"submit\" name=\"edit_mail\" value = \"Edit\"/></td>
<td>{$row['pro']}</td><td>{$row['pro_update']}</td><td>{$row['ana']}</td>
<td>{$row['ana_update']}</td><td>{$row['cell']}</td><td>{$row['cell_update']}</td><td>{$row['cellother']}</td>
<td>{$row['cellother_update']}</td><td>{$row['gen']}</td><td>{$row['gen_update']}</td><td>{$row['genother']}</td>
<td>{$row['genother_update']}</td><td>{$row['author']}</td><td>{$row['author_update']}</td><td>{$row['other']}</td><td>{$row['other_update']}</td>
<td><input type=\"submit\" name=\"delete_mail\" value =\"Delete\"/></td>
<td><input type =\"hidden\" name = \"id\" value=\"{$row['id']}\"/></td>
</tr>";
}
}
echo "</table>";
echo "</form>";
And this is where the delete command comes into place (excerpt):
} elseif(isset($_SESSION['user_id']) AND isset($_POST['delete_mail'])){
//user is deleting existing queries
$conn=db_connect_2();
$id = mysqli_real_escape_string($conn, $_POST['id']);
echo $id;
$sql2 = "DELETE FROM mailing_list WHERE id='$id'";
$result = mysqli_query($conn, $sql2) or mysqli_error($conn);
$msgs[] = "Query deleted successfully.";
$body = "account.php";
}
yes it can delete entries all right
but it doesn't delete a specific entry when i click the "delete" button near it
somehow, it ALWAYS deletes the last row of entry at the table
as you can see, i echoed out $id as it's referring to the LAST entry as well
So my question is, how to delete a particular entry when i click the corresponding "delete" button??
Thanks