My script produces a checkbox for each email address added to the database when a user clicks on a particular checkbox and clicks the delete button a radio button appears which asks the user to confirm that they want to delete the email address.
checkbox[email] ali4@hotm.uk[/email]
checkbox[email] ali5@hotm.uk[/email]
delete(button when clicked the radio confirmation appears)
Are you sure you want to delete this email address (s)?
Yes No (radio buttons)
submit (button)
However, with my script when the user clicks delete the checkbox that was checked gets unchecked and the radio button yes and no requires that a checkbox is slected before the email address gets selected.
Here's the code-
<?
// Check if the form has been submitted.
if (isset($_POST['Insert'])) {
if ($_POST['sure'] == 'Yes') { // Delete them.
$dels = $_POST['e'];
foreach($dels as $key => $value) {
$value = mysql_real_escape_string($value);
$delete_query = "DELETE FROM mailinglists WHERE seminarID= 1 AND emailAddress='$value'";
//echo $delete_query;
//echo '<br />';
//echo $value;
$delete_result=@mysql_query($delete_query,$dbc);
}
if (mysql_affected_rows() == 1) { // If it ran OK.
// Print a message.
echo '<h1 id="mainhead">Delete a User</h1>
<p>The email address has been deleted.</p><p><br /><br /></p>';
} else { // If the query did not run OK.
echo '<h1 id="mainhead">System Error</h1>
<p class="error">The user could not be deleted due to a system error.</p>'; // Public message.
echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; // Debugging message.
}
} else { // Wasn't sure about deleting the email address.
echo '<h1 id="mainhead">Delete a email address</h1>
<p>The email address has NOT been deleted.</p><p><br /><br /></p>';
}
}
?>
<!-- action attribute needs to know which script the form data will go to. -->
<form method="post" action="mailingLists.php" name="form2" onSubmit="return checkboxVal()">
<?
$select_query= "SELECT emailAddress FROM mailinglists WHERE seminarID =1";
$select_result=@mysql_query($select_query,$dbc);
//if (mysql_num_rows($select_result) > 0) {
if (mysql_affected_rows() > 0) {
echo '<table width="403" border="0" align="center" bgcolor="#ffffff">';
// this retrieves the results
while ($row=mysql_fetch_array($select_result, MYSQL_ASSOC)) {
$eAdd = $row['emailAddress'];
// create a row for printing the results (email addresses)
echo '<tr><td align="left"><input type="checkbox" name="e[]" value="';
echo $eAdd;
echo '" title=' . $eAdd . '>';
echo $eAdd . '</input>
</td></tr>';
}
echo '<tr><td>
<input name="Delete" type="submit" value="Delete selected email address (s)" >
</td></tr>';
}
// checks whether to process the delete function
if(isset($_POST['Delete'])) {
echo '<tr><td><br />
<p>Are you sure you want to delete this email address (s)?<br />
<input type="radio" name="sure" value="Yes" /> Yes
<input type="radio" name="sure" value="No" checked="checked" /> No</p>
<p><input type="submit" name="submit" value="Submit" /></p>
<p><input type="hidden" name="Insert" value="TRUE" /></p>
</td></tr></table>
';
}
?>
</form>
thanks in advance