Okay, so instead of the ID's of each record showing up in the form that is dosplayed for the user, there are radio buttons. I want to create it as when the user clicks on one of the radio buttons, that record is selected. Then the user, clicks on the delete button and gets redirected to another page in which it displayes the content of that record.
For example:

First Name: (value of first name in record)
Last Name: (value of last name in record)

And then there will be a button on the bottom that says, Confirm delete. And then when the user clicks that button, the record will get deleted.

I just don't know how to use the radio buttons that contain the ID of each record to do this..

Dani AI

Generated

The core problem in the thread is not the radios themselves but where they live. was right to suggest using the DB ID as the radio value, but in 's snippet the radio inputs are outside the form that submits the "Delete" button — so p06_confirm.php receives no selected ID. The form that submits must include the radio inputs (or the selected ID must be copied into a hidden field) so the POST contains the chosen record ID.

Recommended flow and checks:

  • Wrap the table of rows (radio inputs) and the action buttons in a single form, or submit the selected ID explicitly to the confirm page.
  • On p06confirm.php validate the incoming ID as an integer (do not trust raw POST). Use prepared statements (PDO or mysqli) instead of deprecated mysql* functions and avoid the error-suppression operator (@).
  • Fetch the record by ID, display its fields escaped with htmlspecialchars, then show a small confirm-delete form that posts the ID again to a delete handler. The delete handler must re-validate the ID, check the row exists, and perform the deletion with a prepared DELETE statement. Use a CSRF token and do not run deletions as the DB root user.

Example (confirm page: fetch and show, then present confirm form):

<?php
$id = filter_input(INPUT_POST, 'idselect', FILTER_VALIDATE_INT);
if (!$id) { echo "No record selected."; exit; }

$pdo = new PDO('mysql:host=localhost;dbname=project6;charset=utf8mb4','dbuser','dbpass',[
  PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);

$stmt = $pdo->prepare('SELECT c.First_Name, c.Last_Name, ci.Name AS City FROM contacts c JOIN cities ci ON c.citiesID = ci.citiesID WHERE c.ID = ?');
$stmt->execute([$id]);
$rec = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$rec) { echo "Record not found."; exit; }
?>
<p>First Name: <?php echo htmlspecialchars($rec['First_Name'], ENT_QUOTES); ?></p>
<p>Last Name: <?php echo htmlspecialchars($rec['Last_Name'], ENT_QUOTES); ?></p>
<form method="post" action="p06_delete.php">
  <input type="hidden" name="id" value="<?php echo (int)$id; ?>">
  <input type="submit" name="confirm" value="Confirm delete">
</form>

Extra tips: show a friendly message if no radio is selected, redirect after successful delete to avoid resubmission, and add a small client-side bit of JS to disable the Delete button until a radio is chosen for a better UX.

Recommended Answers

All 2 Replies

Member Avatar for Member #120589

Are you sure you want radiobuttons or checkboxes?

Anyway, as you create your set of radiobuttons, use the 'id' from the DB table as the 'value' of the radiobutton as you loop over all the records available for deletion:

$rads = "<table><thead><tr><th>...other headings...</th><th>Delete</th><tr></thead><tbody>";
while($d = mysql_fetch_array($result)){
  $rads .= "<tr><td>...rest of table...</td><td><input type=\"radio\" name=\"deletes\" value=\"{$d['id']}\" /></td></tr>";
} 
$rads .= "</tbody></table>";

Something like that?

You just pick up the value in another page with $_POST. Clean this variable and then use it to extract the relevant record from the DB. Show it and add a confirm delete button. You can use a hidden field to hold the 'soon-to-be-deleted' id of the record. The confirm delete button sends the id value to a page that picks it up via something like $_POST;

I don't fully understand.

My code is like this:

<table border="1" />
<th>ID</th> <th> First Name </th> <th>Last Name </th> <th> Address </th> <th> Postal code </th> <th>Phone</th> <th>E-mail Address</th><th> City </th><th>Province</th> 

<?php
@$record_action=$_POST['select'];
@$id_select=$_POST['idselect'];

$db=mysql_connect("localhost","root") or die(mysql_error());
					
mysql_select_db("project6",$db) or die (mysql_error());
$SQL="SELECT * 

FROM  `contacts` 

INNER JOIN cities ON contacts.citiesID = cities.citiesID

ORDER BY contacts.Last_Name";
$result=mysql_query($SQL) or die(mysql_error());
$num_results=mysql_num_rows($result);

					
for ($i=0;$i<$num_results;$i++)

{

$row=mysql_fetch_array($result);

 echo "<tr><td><input type='radio' name='idselect' value='".$row["ID"]."' /></td><td>".$row["First_Name"]."</td><td>".$row["Last_Name"]."</td><td>".$row["Address"]."</td><td>".$row["Postal_Code"]."</td><td>".$row["Phone"]."</td><td>".$row["Email_Address"]."</td><td>".$row["Name"]."</td><td>".$row["Province"]."</td></tr>";

}
 mysql_close($db);

?>
</table>
<form name="addform" action="p06_form.php" method="POST">

<input type='submit' name='select' value='Add' /><br/>

</form>

<form name="deleteform" action="p06_confirm.php" method="POST">
<input type='submit' name='select' value='Delete' /><br/>

<?php echo "&nbsp"; ?><br/>

<input type='submit' name='select' value='Edit' /><br/>
</form>

The user has to select the record they wish to delete by clicking the radio button and clicking the delete button. Then they will get redirected to another form in which the record that they have selected with be displayed with a button below saying "confirm delete" or something. I just don't know how to display the selected record in the next page.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.