question#1 is about an "empty form" => submit button which I want to use to delete records in my DB. Below code(home.php) is from a loop to display the contents of the DB. I want a submit button to be displayed on the last column for every row of data, to be used to delete the particular record(row). Hence my below code:
Code: Select all
<tr>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $rowid; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $field1name; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $field2name; ?></font></td>
<td>
<form action="deleteRecordButton.php" method="post">
<input type="submit" />
</form>
</td>
</tr>
and my deleteRecordButton code is:
Code: Select all
<?php
$id=$_POST['id'];
$con = mysql_connect("127.0.0.1","abc","def")
or die ('ERR: Could not connect to server. '.mysql_error());
mysql_select_db('my_db',$con)
or die ('ERR: Could not use database. '.mysql_error());
mysql_query("DELETE FROM contacts WHERE mytable=$id");
mysql_close($con);
?>
Is there a better way to do the above?
thanks
Tokunbo