mpsn Posted June 19, 2011 Share Posted June 19, 2011 =========================== Hi, what I want to do is on the display.php page to let admin choose which entries to delete, but when they click DELETE button, a DELETE NOW button becomes visible and the entries checked will only be deleted when admin click DELETE NOW button, but I don't know why the DELETE BUTTON doesn't show up when admin clicks DELETE. Please help!!!!! <?php session_start(); include_once('config.php'); //NB: this includes the constant: domain ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Bell Mobility - By Andy 2</title> <link rel="stylesheet" type="text/css" href="BellATuCSS.css" /> <script type="text/javascript" src="BellATuJS.js"></script> </head> <body> <img src="Bell_Logo.jpg" title="Welcome to Bell Mobility!"/> <div> <form> <input type="button" onclick="location='<?php echo DOMAIN?>/bellInsertForm.php'" value="Insert new entry" /> <input type="button" onclick="window.open('<?php echo DOMAIN?>/bellPublicHome.php')" value="Public" /> <input type="button" onclick="window.open('<?php echo DOMAIN?>/purchaseditem.php')" value="View Purchased Items" /> </form> </div> <hr /> <form method="POST" action=""> <!--NB: checkbox form for multiple delete/update/insert--> <table border="border"> <input type='submit' value='DELETE' name='delete0' /> <!--name has suffix 0 to not get get mixed up with the submit name in update/delete php--> <!--<input type="submit" value="UPDATE" name="update0" />--> <?php require 'bellSessionDisconnect.inc'; require 'bellConnect.inc.php'; //NB: only show DELETE NOW to confirm admin wishes to delete all checked entries echo "<div id='confirmDelete' style='display:none'> <form method='post'> <input type='submit' value='DELETE NOW' name='deleteNow' /> <input type='button' name='Cancel' value='Cancel' onclick='window.location='http://localhost/bell/display.php'' /> </form> </div>"; //NB: if DELETE button pressed, then delete all the entries with the ID's captured from the $_POST array named // modifyArray (this is name attribute of checkbox input type) if(isset($_POST['delete0']) && !empty($_POST["modifyArray"]))//when admin presses DELETE button and there is at least one // entry selected, then show the confirmation to delete { echo "<script type='text/javascript'> document.getElementById('confirmDelete').style.display='visible'; </script>"; $modifyArray = $_POST["modifyArray"]; echo "Are you sure you want to delete "; foreach ($modifyArray as $curCheckBoxItem) { $result=mysql_query("SELECT Manufacturer, Name FROM bellProducts WHERE ID='$curCheckBoxItem'"); $row=mysql_fetch_assoc($result); echo $row['Manufacturer']." ".$row['Name'].", "; }//END FOR EACH loop echo "?"; //NB: Only actually delete checked entries iff user clicks DELETE NOW button if($_POST['deleteNow']) { //NB: traverse the checked items to delete foreach ($modifyArray as $modifyArrayed) { $sql = "DELETE FROM bellProducts WHERE ID='$modifyArrayed'"; $result = mysql_query($sql); }//END FOR EACH loop //NB: show Deleted status if($result) { echo "Deleted successfully."; } else if(!$result) //NB: how do I only display the error messages I want, not php error messages... echo "No items selected to delete."; }//END BIG IF for DELETE NOW button }//END BIG IF for DELETE button //NB: outputting a nice html table of db table $result=mysql_query("SELECT ID, Image, Name, Manufacturer, Price, Description, SimSupport FROM bellProducts"); //phpinfo(); //NB: print table headings if(mysql_num_rows($result))//if there is at least one entry in bellProducts, make a table { //$counter+=1; print "<table border='border'>"; print "<tr> <th>ID</th> <th>Select entries to delete</th> <th>Image</th> <th>Name</th> <th>Manufacturer</th> <th>Price</th> <th>Description</th> <th>Sim Support</th> <th colspan='2' align='center'>Modify</th> </tr>"; //NB: now output each row of records while($row=mysql_fetch_assoc($result))//NB: while this row still has fields to go through { //extract($row); print "<tr align='center'> <td>$row[iD]</td> <td><input type='checkbox' name='modifyArray[]' value='$row[iD]' id=\"modifyArray[]\"/></td> <td>"; if(!empty($row['Image'])) { $curImage=$row['Image']; } else if(empty($row['Image'])) { $curImage='fileUploadIcon.jpg'; //$title="please upload item image"; } print "<img src=$curImage width='70px' height='90px' title='please upload product image' /> </td> <td> $row[Name] </td> <td> $row[Manufacturer] </td> <td> $$row[Price]</td> <td align='left'>$row[Description]</td> <td>$row[simSupport]</td> <td><a href='bellUploadForm.php?ID=$row[iD]'>UPLOAD IMAGE</a></td> <td><a href='bellUpdateForm.php?ID=$row[iD]'>UPDATE</a></td> </tr>"; //}//END INNER IF }//END WHILE }//END BIG IF ?> </table> </form> </body> </html> <?php mysql_close();?> Quote Link to comment https://forums.phpfreaks.com/topic/239822-problem-with-confirm-delete-button-to-show-up-on-same-page/ Share on other sites More sharing options...
monkeytooth Posted June 19, 2011 Share Posted June 19, 2011 In order to get the button to show up directly after the other button is clicked without reloading the page is to impliment some javascript to manipulate the already rendered DOM. PHP is a server-side script. Meaning it loads, runs its scripts, then renders in the browser. But once its rendered its rendered. JavaScript is just the opposite I mean you can use it to do things to the page when it loads but essentially JavaScript works on the browser elements (DOM) after the page is rendered. My Suggestion to you would look into jQeury its a fairly stable and all around good library to work with when you want to manipulate your pages like I think your trying to. Just for refrence jQuery is also JavaScript but its a library of premade functionality that you can reuse with less hassle Quote Link to comment https://forums.phpfreaks.com/topic/239822-problem-with-confirm-delete-button-to-show-up-on-same-page/#findComment-1231931 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.