GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 14-Sep-2004, 03:47
jlee jlee is offline
New Member
 
Join Date: Jul 2004
Posts: 9
jlee is on a distinguished road

Are you sure?


Hi guys

Just a simple one I think:

I have a simple form that the user enters an id number in and clicks a submit button to delete the entry from a database.

I need some form of check that asks the user "are you sure you want to delete this entry" with a yes and no option. If the no option is selected then it needs to not delete it obviously and return to where teh user was, but if they click yes then it needs to continue. Any help would be appreciated - thanks
  #2  
Old 15-Sep-2004, 10:42
Garth Farley Garth Farley is offline
Invalid Email Address
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
This isn't too tough really. What you really want is to preserve the inputted data across one page (the one which asks you to confirm). It can be easily done like so:
PHP Code:

if(isset($_POST['Delete']) && !isset($_POST['Yes']) && !isset($_POST['No'])){  
    //so form has been submitted, but we've not yet confirmed
    //Print confirmation form, which has all the previous values hidden:

    //Do checks first on inputs
    $del_id = $_POST['del_id'];

    echo 'Are you sure you wish to delete record number '. $del_id .'?<br />';
    echo '<form target="'. $_SERVER['PHP_SELF'] .'" method="post">'.
           '<input type="hidden" name="del_id" value="'. $del_id .'">'.
           '<input type="hidden" name="Delete">'.
           '<input type="submit" name="Yes"> <input type="submit" name="No">';

} 
elseif(isset($_POST['Delete']) && isset($_POST['Yes'])){
    //Form has been submitted & confirmed!

    delete($_POST['del_id']); //your function
}
elseif(isset($_POST['Delete']) && isset($_POST['No'])){
    //Deletion was cencelled
    echo 'Deletion cancelled';
}
else{  //default, print form asking for recored number to be deleted

    echo 'Please enter the record ID you wish to delete<br />';
    echo '<form target="'. $_SERVER['PHP_SELF'] .'" method="post">'.
           '<input type="text" name="del_id">'.
           '<input type="submit" name="Delete">';
} 



Do you see what I'm at?
Note that I get confused with how submit buttons give values, so the above may not be perfect.
GF
 

Recent GIDBlogFirst week of IA training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:11.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.