Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    Brighton
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    "Are you sure you want to delete this record...?"

    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 Code:
    <?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>
    <?
        
    }
        
    ?>

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I found this...I hadn't tested it yet.

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

    PHP Code:
    <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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •