Guest User

Untitled

a guest
Apr 21st, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. <?php // Script 13.11 - index.php
  2.  
  3. session_start(); // start session
  4.  
  5. confirm_logged_in();
  6.  
  7.  
  8. function logged_in() {
  9. return isset($_SESSION['id']);
  10. }
  11.  
  12. function confirm_logged_in() {
  13. if (!logged_in()) {
  14. redirect_to("login2.php");
  15. }
  16. }
  17. function redirect_to( $location = NULL ) {
  18. if ($location != NULL) {
  19. header("Location: {$location}");
  20. exit;
  21. }
  22. }
  23.  
  24. /* This is the home page for this site. It displays:
  25. - The most recent quote (default)
  26. - OR, a random quote
  27. - OR, a random favorite quote */
  28.  
  29. // Include the header:
  30. include('templates/header.html');
  31.  
  32. // Need the database connection:
  33. include('../mysql_connect.php');
  34.  
  35. // Define the query:
  36. $query = 'SELECT contact_id, name, company, phone, email, address FROM contactstable ORDER BY name ';
  37.  
  38. // Run the query:
  39. if ($result = mysql_query($query, $dbc)) {
  40.  
  41. while($row = mysql_fetch_array($result))
  42. {
  43. echo $row['name'];
  44. echo " " . $row['company'];
  45. echo " " . $row['phone'];
  46. echo " " . $row['email'];
  47. echo " " . $row['address'];
  48. echo "<br />";
  49.  
  50. } // End of while loop.
  51. ?>
  52. <form action="index2.php" method="post"><input type="text" name="search"><input type="submit" value="Search"></form>
  53. <?php
  54. // If the admin is logged in, display admin links for this record:
  55. if (is_administrator()) {
  56. print "<p><b>Quote Admin:</b> <a href=\"edit_contact.php?id={$row['contact_id']}\">Edit</a> <->
  57. <a href=\"delete_entry.php?id={$row['contact_id']}\">Delete</a>
  58. </p>\n";
  59. }
  60.  
  61. } else { // Query didn't run.
  62. print '<p class="error">Could not retrieve the data because:<br />' . mysql_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>';
  63. } // End of query IF.
  64.  
  65. mysql_close($dbc); // Close the connection.
  66.  
  67.  
  68. include('templates/footer.html'); // Include the footer.
  69. ?>
Add Comment
Please, Sign In to add comment