dare87 Posted August 21, 2007 Share Posted August 21, 2007 I have a page that list a bunch of information from a database. It has the information, edit, and delete. I would like to make it so there is a onclick confirm.. for some reason it is not working. Will you please look at it and let me know if I am doing something wrong.<br><br> <?php // Include the PHP script that contains the session information. include('includes/session_admin.php'); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>The Date Tiki - Your Dating Resource</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" type="text/css" href="includes/base.css" title="Default" media="screen" /> <script type="text/javascript" src="includes/include.js"></script> </head> <body> <?php include('includes/top.php'); ?> <div id="main"> <div id="sideBarLeft"><?php include('includes/left.php'); ?></div> <div id="content"> <div class="innerContent"> <div class="title">Review Business Listings</div> <?php // Connect to the database. require_once ('../../datemysql_connect.php'); // The number of pages to display per page. $display = 20; // Calculate how many pages will be needed. // If the number of pages has not been calculated, then it will need to calculated. if (isset($_GET['np'])) $num_pages = $_GET['np']; else // Needs to be calculated. { // Count the number of records in the database. $query = "SELECT COUNT(*) FROM listing ORDER BY date_entered DESC"; $result = mysql_query ($query); $row = mysql_fetch_array ($result, MYSQL_NUM); $num_records = $row[0]; // Calculate the number of pages to use. if ($num_records > $display) $num_pages = ceil ($num_records / $display); else $num_pages = 1; } // Determine in the database to start returning results. if (isset($_GET['s'])) $start = $_GET['s']; else $start = 0; // Make the query. $query = "SELECT b_id AS bid, bname, address, city, state, zip, phone, phone2, fax, website, email, DATE_FORMAT(date_entered, '%M %d, %Y') AS date, discription, activities, photo, directions, map, hours FROM listing WHERE approved=1 ORDER BY date_entered ASC LIMIT $start, $display"; // Run the query. $result = @mysql_query ($query); // If the query ran w/o error, print out the results. if ($result) { // Table header. echo ' <table width="100%" align="center" cellspacing="0" cellpadding="5"> <tr> <td align="left"><b> </b></td> <td align="left"><b> </b></td> <td align="left"><b>Business</b></td> <td align="left"><b>City</b></td> <td align="left"><b>Date Submitted</b></td> </tr>'; // Fetch and print all the records. $bg = '#dee4ed'; // Set the background color. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { // Alternate the background color. $bg = ($bg == '#dee4ed' ? '#ffffff' : '#dee4ed'); if (isset($_SESSION['userId']) && $_SESSION['accessLevel'] == 0 && (substr($_SESSION['PHP_SELF'], -10) != 'logout.php') ) // Administrator { echo ' <tr bgcolor="' . $bg . '"> <td align="left"> <a href="b_edit.php?bname=' . $row['bname'] . '&city=' . $row['city'] . '&bid=' . $row['bid'] . '" onClick="javascript:return confirm("Are you sure?")">Edit</a></td> <td align="left"><a href="auxiliary/b_delete.php?bid=' . $row['bid'] . '">Delete</a></td> <td align="left">' . $row['bname'] . '</td> <td align="left">' . $row['city'] . '</td> <td align="left">' . $row['date'] . '</td> </tr>'; } else { echo ' <tr bgcolor="' . $bg . '"> <td align="left"><a href="b_edit.php?bname=' . $row['bname'] . '&city=' . $row['city'] . '&bid=' . $row['bid'] . '">Edit</a></td> <td align="left"><a href="#">Delete</a></td> <td align="left">' . $row['bname'] . '</td> <td align="left">' . $row['city'] . '</td> <td align="left">' . $row['date'] . '</td> </tr>'; } } // Close the table. echo '</table>'; // Free up the resources. mysql_free_result ($result); // Make links to other pages, if necessary. if ($num_pages > 1) { echo '<br /><p>'; // Determine what page the script is on. $current_page = ($start / $display) + 1; // If it's not the first page, create a previous button. if ($current_page != 1) echo '<a href="b_review.php?s=' . ($start - $display) . '&np=' . $num_pages . '">Previous</a> '; // Make all the numbered pages. for ($i = 1; $i <= $num_pages; $i++) if ($i != $current_page) echo '<a href="b_review.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '">' . $i . '</a> '; else echo $i . ' '; // If it's not the last page, make a Next button. if ($current_page != $num_pages) echo '<a href="b_review.php?s=' . ($start + $display) . '&np=' . $num_pages . '">Next</a> '; echo '</p>'; } } else { // If the query did not run successfully, print out an error message. echo 'The Business Names could not be retrieved.'; } // Close the database connection. mysql_close(); ?> </div><div id="footer"><?php include('includes/bottom.php'); ?></div> </div> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
micah1701 Posted August 21, 2007 Share Posted August 21, 2007 the JavaScript confirm() function returns true or false based on the users selection. so you need to do something like: <script> function sure(){ var x = confirm("are you sure"); if(!x){ return false; } } </script> <?php echo " <a href="b_edit.php?bname=' . $row['bname'] . '&city=' . $row['city'] . '&bid=' . $row['bid'] . '" onClick="return sure()">Edit</a></td> "; ?> onClick="javascript:return confirm("Are you sure?")" Quote Link to comment Share on other sites More sharing options...
dare87 Posted August 22, 2007 Author Share Posted August 22, 2007 Worked Great Thanks Quote Link to comment 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.