...

View Full Version : "Are you sure you want to delete this record...?"



dysfunctionGazz
06-23-2006, 01:35 AM
Hi everyone

With the help of forum members I now have a working view/edit script, which I have also added a delete function to.

Already I have managed to delete one record in error whilst playing with it (doh!) which luckily doesnt matter - but obviously I want to prevent a recurrence as we will be relying on the database quite a lot for our touring etc!!!

I understand that because PHP is server side and people can turn of javascript, that a pop-up alert box is not the best way to do it. Instead I would like it to go to a confirmation page with a seperate "yes/no" buttons to confirm record update/delete.

I am not quite sure how to do this from this script. This is what I have, if someone could guide me in which bits of the script to put into a seperate file, and how to ensure variables are passed to it correctly etc that would be great, thanks!


<?php
include 'dbloginscript.php';
if(isset($_POST['save']))
{
$id = $_GET['cid'];
$showdate = mysql_escape_string($_POST['showdate']);
$venue = mysql_escape_string($_POST['venue']);
$location = mysql_escape_string($_POST['location']);
$showinfo = mysql_escape_string($_POST['showinfo']);

$updating_gig = mysql_query("UPDATE shows SET showdate = '$showdate',
venue = '$venue', location = '$location', showinfo = '$showinfo' WHERE showID = '$id'")
or die (mysql_error());

if(!$updating_gig)
{
die('There has been an error in updating gig entry. Please contact the webmaster.');
}
else
{
echo 'Gig has been updated!';
}
}
else
if(isset($_POST['delete']))
{
$id = $_GET['cid'];
$showdate = mysql_escape_string($_POST['showdate']);
$venue = mysql_escape_string($_POST['venue']);
$location = mysql_escape_string($_POST['location']);
$showinfo = mysql_escape_string($_POST['showinfo']);

$deleting_gig = mysql_query("DELETE from shows WHERE showID = '$id'")
or die (mysql_error());

if(!$deleting_gig)
{
die('There has been an error in deleting gig entry. Please contact the webmaster.');
}
else
{
echo 'Gig has been deleted!';
}
}
else
{
$id = $_GET['cid'];
$gig_details = mysql_query("SELECT * FROM shows WHERE showID= '$id' ");
while ($line = mysql_fetch_array($gig_details)) {
$id = $line["showID"];
$showdate = $line["showdate"];
$venue = $line["venue"];
$location = $line["location"];
$showinfo = $line["showinfo"];
echo'';
}
?>

<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" name="gig_entry" id="gig_entry">
<table width="55%" border="1" align="center" cellpadding="4" cellspacing="0" class="newsheader">
<tr>
<td align="left" valign="top" colspan="2"><b>EDIT/DELETE SHOWS</b></td>
</tr>
<tr>
<td align="left" valign="top"><strong>Date:<br>
<font size="1">(YYYY-MM-DD) </font></strong></td>
<td align="left">
<input name="showdate" type="text" class="regulartextbold" id="showdate" value="<?=$showdate ?>">
</td>
</tr>
<tr>
<td width="29%" align="left" valign="top"><strong>Venue:</strong></td>
<td align="left">
<input name="venue" type="text" class="regulartextbold" id="venue" value="<?=$venue ?>">
</td>
</tr>
<tr>
<td align="left" valign="top"><strong>Location:</strong></td>
<td align="left">
<input name="location" type="text" class="regulartextbold" id="location" value="<?=$location ?>" size="30">
</td>
</tr>
<tr>
<td align="left" valign="top"><strong>Show Info:</strong></td>
<td align="left">
<textarea name="showinfo" cols="50" rows="10" id="showinfo" class="regulartextbold"><?=$showinfo ?>
</textarea>
</td>
</tr>
<tr>
<td align="left" valign="top">&nbsp;</td>
<td>
<input type="submit" name="save" value="Edit Gig">&nbsp;<input type="submit" name="delete" value="Delete Gig">
</td>
</tr>
</table>
</form>
<?
}
?>

raf
06-23-2006, 12:32 PM
seems to me you've got microsoftitis :)

anyway: why not just store the formvalues in (hiden) formfields when you load the page with the 2 buttons? then you can just use the formprocessing code for your delete and update on the third page.
also, for important info, i never delete records. i just use a flag (a column that is initiated at '1' and is set to '0' when the record should be deleted) or i move the record to a 'trash'-table

lansing
06-24-2006, 01:44 AM
I found this...I hadn't tested it yet.

http://psacake.com/web/fw.asp


<form>
<INPUT Type=Submit Value="Add Record"
onClick="this.form.action='addrecord.asp';">

<INPUT Type=Submit Value="Del Record"
onClick="this.form.action='deleterecord.asp';">
</form>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum