PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mmc01ms
Forum Commoner
Posts: 97 Joined: Wed Dec 01, 2004 3:33 am
Location: Nottingham, UK
Post
by mmc01ms » Thu Jan 13, 2005 3:56 pm
I have button which deletes a record from the database however i want some form of validation which would basically ask if they are sure they want to delete. Don't know how i could do this any ideas or examples?
code for delete_vinyl.php is:
Code: Select all
<?php
session_start();
require('page.inc');
require_once('update_delete_fns.php');
checkAdminLogin();
$editform = new Page();
$editform -> Display();
display_main_menu();
if (isset($_POSTї'cat_no']))
{
$catno = $_POSTї'cat_no'];
if(delete_vinyl($catno))
echo '<center>Book '.$catno.' was deleted.</center><br />';
else
echo '<center>Book '.$catno.' could not be deleted.</center><br />';
}
do_html_footer();
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jan 13, 2005 4:11 pm
something similar to:
Code: Select all
if(isset($_POSTї'cat_no']))
{
if(isset($_POSTї'do']) && $_POSTї'do'] == 'confirm')
delete_vinyl();
else
// print the confirmation request, that has hidden form fields to set the do value to 'confirm', as well as pass the cat_no value.
}
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Thu Jan 13, 2005 4:34 pm
or you could use some JS and do it on the form page itself:
Code: Select all
<script>
function checkIt(){
if(confirm("are you sure you want to delete")){
document.MyForm.submit();
}
}
</script>
<form name="MyForm" action="delpage.php">
<input type="button" value="Delete This" onClick="checkIt();">
</form>
Burr
mmc01ms
Forum Commoner
Posts: 97 Joined: Wed Dec 01, 2004 3:33 am
Location: Nottingham, UK
Post
by mmc01ms » Fri Jan 14, 2005 4:40 pm
Thanks for the replies guys i like the idea of the JS Pop-up Box however i tried implementing it. Sorry i may sound dumb but i couldn't get the code you said to work in my script. My attempt is below.
Code: Select all
<?php
//display_vinyl_form.php
require_once('shopping_cart_fns.php');
echo '<script>';
function checkIt(){
if(confirm("are you sure you want to delete")){
document.MyForm.submit();
}
}
echo '</script>';
function display_vinyl_form($vinyl = '')
{
$edit = is_array($vinyl);
?>
<center><form align="center" name="newrecord" method="post" action="<?php echo $edit?'edit_vinyl.php' : 'insert_vinyl.php';?>">
<table bordercolor="#FFFFFF" border="1" bgcolor="#7b9815">
<font color="#000000" size="2" face="Courier New, Courier, mono">
<tr>
<td><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Cat_No: </font></td>
<td><input name="cat_no" type="text" maxlength="6" value="<?php echo $vinylї'cat_no']; ?>"></td>
</tr>
<tr>
<td><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Title: </font></td>
<td><input name="title" type="text" maxlength="40" value="<?php echo $edit?$vinylї'title']:' '; ?>"></td>
</tr>
<tr>
<td><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Artist: </font></td>
<td><select name="artist_id">
<?php
$artist_array=get_artists();
foreach ($artist_array as $thisartist)
{
echo '<option value="';
echo $thisartistї'artist_id'];
echo '"';
if ($edit && $thisartistї'artist_id'] == $vinylї'artist_id'])
echo 'selected';
echo '>';
echo $thisartistї'artist_id'];
echo'</option>';
echo"\n";
}
?>
</select>
</td>
</tr>
<tr>
<td><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Genre: </font></td>
<td><select name="genre_ref">
<?php
$genre_array=get_genres();
foreach ($genre_array as $thisgenre)
{
echo '<option value="';
echo $thisgenreї'genre_ref'];
echo '"';
if ($edit && $thisgenreї'genre_ref'] == $vinylї'genre_ref'])
echo 'selected';
echo '>';
echo $thisgenreї'genre_ref'];
echo'</option>';
echo"\n";
}
?>
</select>
</td>
</tr>
<tr>
<td><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Vinyl Status: </font></td>
<td><select name="status_code">
<?php
$status_array=get_status();
foreach ($status_array as $thisstatus)
{
echo '<option value="';
echo $thisstatusї'status_code'];
echo '"';
echo '>';
echo $thisstatusї'status_description'];
echo'</option>';
echo"\n";
}
?>
</select>
</td>
</tr>
<tr>
<td><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Price: </font></td>
<td><input name="price" type="text" maxlength="5" id="price" value="<?php echo $edit?$vinylї'price']: ' '; ?>"></td>
</tr>
<tr>
<td><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Qty: </font></td>
<td><input name="qty" type="text" maxlength="3" id="qty" value="<?php echo $edit?$vinylї'stock_level']: ' '; ?>"></td>
</tr>
<tr>
<td><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Vinyl Information</font></td><td><textarea name="comments" maxlength="225" cols="60" rows="10"><?php echo $vinylї'vinyl_information']?></textarea></td>
</tr>
<tr>
<td <?php if(!$edit) echo 'colspan="2"'; ?> align="center">
<?php
if ($edit)
echo '<input type="hidden" name="oldcatno" value="'.$vinylї'cat_no'].'">';
?>
<td><input type="submit" value="<?php echo $edit?'Update' : 'Add';?>Record"></form><?php if($edit)
{
echo '';
echo '<form name="MyForm" action="delete_vinyl.php"> ';
echo '<input type="button" value="Delete Vinyl" onClick="checkIt();"> ';
echo '<input type="hidden" name="cat_no" value="'.$vinylї'cat_no'].'">';
echo '</form></td>';
} ?>
</tr>
<table></form> </center>
<div align="left"></div></td>
</tr>
</table></td>
</tr>
</table>
<?
}
do_html_footer();
?>
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Fri Jan 14, 2005 4:50 pm
w/o reading the entire set of code you have there, I see an error right off the bat at the top. Because this is js, it needs to be sent to the user, the function is a js function, not a php function so you need to include that in your echo like this:
Code: Select all
echo "<script>
function checkIt(){
if(confirm("are you sure you want to delete")){
document.MyForm.submit();
}
}
</script>";
as I said, I didn't read over all of your code, but make sure that you include everything that needs to call that js function in the stuff that gets sent to the user.
plug away at that and lemme know if you need anythign else.
Burr
edit: not sure if that semi-colon is gonna throw it off in the js itself, best bet would be to just end your php block and include that js function on the page then restart your php block...