Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Set the variables for the database access:
- $host = "localhost";
- $user = "webuser";
- $password = "h59hdg";
- $database = "contactinfo";
- $tablename = "contacts";
- // Connect to database
- mysql_connect($host,$user,$password) or die("Unable to connect to Server.");
- @mysql_select_db($database) or die("Unable to select database: $database");
- // Unset variables for security
- $Host = "";
- $User = "";
- $Password = "";
- ?>
- <?php $title = "All Contacts"; include('head.php'); ?>
- <table>
- <tr><th>Name</th><th>Email Address</th><th>Comments</th></tr>
- <?php
- // Set the variables for the database access:
- include ('connect.php');
- $query = "SELECT * FROM $tablename";
- $result=mysql_query($query);
- $num=mysql_numrows($result);
- $i=0;
- while ($i < $num) {
- // Fetch the results from the database.
- $firstname=mysql_result($result,$i,"firstname");
- $lastname=mysql_result($result,$i,"lastname");
- $emailaddress=mysql_result($result,$i,"emailaddress");
- $comments=mysql_result($result,$i,"comments");
- print("<tr>\n");
- print("<td>$firstname $lastname</td>\n");
- print("<td><a
- href=\"mailto:$emailaddress\">$emailaddress</a></td>\n");
- print("<td>$comments</td>\n");
- print("</tr>\n");
- $i++;
- }
- mysql_close();
- ?>
- </table>
- <p><a href="dbform.php">Add Contact</a></p>
- <?php include('foot.php'); ?>
- <?php $title = "Add New Contact"; include('head.php'); ?>
- <form action="dbinsert.php" method=post>
- <table>
- <tr><th>First Name</th><td><input type=text name="firstname"
- size=20></td></tr>
- <tr><th>Last Name</th><td><input type=text name="lastname" size=40></td></tr>
- <tr><th>E-mail Address</th><td><input type=text name="email"
- size=60></td></tr>
- <tr><th>Comments</th><td><textarea name="comments" rows=5
- cols=40></textarea></td></tr>
- <tr><th></th><td><input type=submit name="submit" value="Add"></td></tr>
- </table>
- </form>
- <?php include('foot.php'); ?>
- <?php $title = "Contact Add Result"; include('head.php'); ?>
- <?php
- /* This page receives and handles the data generated by "dbform.html". */
- // Trim extra spaces from the incoming data.
- $firstname = trim ($_POST["firstname"]);
- $lastname = trim ($_POST["lastname"]);
- $email = trim ($_POST["email"]);
- $comments = trim ($_POST["comments"]);
- include ('connect.php');
- $query = "INSERT INTO $tablename VALUES ('0', '$firstname', '$lastname',
- '$email', '$comments'
- )";
- print ("The query is:<br />$query<p>\n");
- if (mysql_query($query)) {
- print ("The query was successfully executed!<br />\n");
- } else {
- print ("The query could not be executed!<br />\n");
- }
- mysql_close ();
- ?>
- <p>
- <a href="dbform.php">Add Another Contact</a>
- <a href="index.php">View All</a>
- </p>
- <?php include('foot.php'); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement