If this turns out to be a JavaScript issue and not a PHP issue, I appologize in advance.
I'm trying to setup a web interfance for maintaining a database - adding records, editing records, deleting records, etc.. This way, non-technical people can do most of the upkeep without having to get into the code. I've got most of it working, but I'm having a problem with the delete a record task.
The first step is to give the user a list of records and the option to edit or delete each individual record. The user interface (the actual webpage, not the code), looks basically like this:
edit | delete -- Name of Record 1
edit | delete -- Name of Record 2
edit | delete -- Name of Record 3
edit | delete -- Name of Record 4
etc...
The edit link takes the user to a page where they edit the specified record - I have that working just fine. The delete link deletes the specified record - I have that working just fine as well. Each link passes an action (either "edit" or "delete") and a record ID to a php script. The script then executes a set of commands based on the action, and works with a certain record based on the record ID.
The logic is basically this
if ($action == "edit") {
do all this stuff
} else if ($action == "delete") {
delete the record
} else {
echo "Can't read \$action"; // used for error checking
}
OK, so to this point, everything is fine and dandy.
Here's where my problem comes in. I want to use a javascript confirmation box to force the user to confirm that they do want to delete the specified record (in case they clicked "delete" inadvertantly, or clicked to delete the wrong record). Once they click the delete link, I want the confirmation box to pop up asking if they are sure they want to delete such and such a record. If they click OK, then the script will continue and the record will be deleted. If they click cancel, I want them take back to (or left at) the list of records with the edit | delete links.
Make sense?
I tried doing this (this is all part of a loop, so there's other stuff going on, but this should be the relevant code):
do {
printf("<tr>\n");
printf(" <td width=\"70\"><font size=\"-1\"><a href=\"EditDB.php?action=edit&ID=%s\">edit</a> | <a onclick=\"return ConfirmDeletion(%s)\" href=\"EditDB.php?action=delete&ID=%s\">delete</a>\n ", $record["MajorID"],$record["Major"],$record["MajorID"]);
printf(" <td width=\"200\"><font size=\"-1\">%s\n",$record["Major"]);
printf("</td>\n");
}
:::Sorry, for some reason, I can't get the formatting to work to make it more readable:::
That sort of worked. Once the user clicks the delete link, they are prompted with the confirmation box. However, the record is deleted regardless of whether the users clicks OK or Cancel in the confirmation box.
Man... this is turning into a novel...
So, here's what I want to try next, but I'm not sure how to go about it. I want to change the logic I mentioned above to something like this:
if ($action == "edit") {
do all this stuff
} else if ($action == "delete") {
pop up confirmation box
if (user clicks OK) {
delete the record
} else {
take user back to list of records
}
} else {
echo "Can't read \$action"; // used for error checking
}
Problem is, I don't know how to do that, specifically, I don't know how to use the value returned from the confirmation box as the conditional in the if statement.