Advertisement
Guest User

Untitled

a guest
May 18th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. <?php
  2. // Set the variables for the database access:
  3. $host = "localhost";
  4. $user = "webuser";
  5. $password = "h59hdg";
  6. $database = "contactinfo";
  7. $tablename = "contacts";
  8. // Connect to database
  9. mysql_connect($host,$user,$password) or die("Unable to connect to Server.");
  10. @mysql_select_db($database) or die("Unable to select database: $database");
  11. // Unset variables for security
  12. $Host = "";
  13. $User = "";
  14. $Password = "";
  15. ?>
  16.  
  17.  
  18. <?php $title = "All Contacts"; include('head.php'); ?>
  19.  
  20.  
  21. <table>
  22. <tr><th>Name</th><th>Email Address</th><th>Comments</th></tr>
  23. <?php
  24. // Set the variables for the database access:
  25. include ('connect.php');
  26. $query = "SELECT * FROM $tablename";
  27. $result=mysql_query($query);
  28. $num=mysql_numrows($result);
  29. $i=0;
  30. while ($i < $num) {
  31. // Fetch the results from the database.
  32. $firstname=mysql_result($result,$i,"firstname");
  33. $lastname=mysql_result($result,$i,"lastname");
  34. $emailaddress=mysql_result($result,$i,"emailaddress");
  35. $comments=mysql_result($result,$i,"comments");
  36. print("<tr>\n");
  37. print("<td>$firstname $lastname</td>\n");
  38. print("<td><a
  39. href=\"mailto:$emailaddress\">$emailaddress</a></td>\n");
  40. print("<td>$comments</td>\n");
  41. print("</tr>\n");
  42. $i++;
  43. }
  44. mysql_close();
  45. ?>
  46. </table>
  47. <p><a href="dbform.php">Add Contact</a></p>
  48. <?php include('foot.php'); ?>
  49.  
  50.  
  51. <?php $title = "Add New Contact"; include('head.php'); ?>
  52. <form action="dbinsert.php" method=post>
  53. <table>
  54. <tr><th>First Name</th><td><input type=text name="firstname"
  55. size=20></td></tr>
  56. <tr><th>Last Name</th><td><input type=text name="lastname" size=40></td></tr>
  57. <tr><th>E-mail Address</th><td><input type=text name="email"
  58. size=60></td></tr>
  59. <tr><th>Comments</th><td><textarea name="comments" rows=5
  60. cols=40></textarea></td></tr>
  61. <tr><th></th><td><input type=submit name="submit" value="Add"></td></tr>
  62. </table>
  63. </form>
  64. <?php include('foot.php'); ?>
  65.  
  66.  
  67.  
  68.  
  69. <?php $title = "Contact Add Result"; include('head.php'); ?>
  70.  
  71.  
  72.  
  73. <?php
  74. /* This page receives and handles the data generated by "dbform.html". */
  75. // Trim extra spaces from the incoming data.
  76. $firstname = trim ($_POST["firstname"]);
  77. $lastname = trim ($_POST["lastname"]);
  78. $email = trim ($_POST["email"]);
  79. $comments = trim ($_POST["comments"]);
  80. include ('connect.php');
  81. $query = "INSERT INTO $tablename VALUES ('0', '$firstname', '$lastname',
  82. '$email', '$comments'
  83. )";
  84. print ("The query is:<br />$query<p>\n");
  85. if (mysql_query($query)) {
  86. print ("The query was successfully executed!<br />\n");
  87. } else {
  88. print ("The query could not be executed!<br />\n");
  89. }
  90. mysql_close ();
  91. ?>
  92. <p>
  93. <a href="dbform.php">Add Another Contact</a>
  94. <a href="index.php">View All</a>
  95. </p>
  96. <?php include('foot.php'); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement