Domain Discussion Board

Go Back   Domain Discussion Board > Web Hosting & Web Design > Scripts

 
Reply
 
LinkBack Thread Tools Display Modes
[PHP] Simple guestbook created for school coursework.
Old
  (#1 (permalink))
Hydro
Member
Hydro is an unknown quantity at this point
 
Status: Offline
Posts: 64
Points: 256.2
Bank: 505.7
Total Points: 761.9
Donate
Join Date: May 2006
Location: Texas
Rep Power: 0
[PHP] Simple guestbook created for school coursework. - 05-29-2006, 08:26 PM

Took me about a lesson and a bit.. (1 lesson = 50 minutes)

Quote:
Originally Posted by create-db.php
<html>
<head>
<title>Create Guesbook table</title>
</head>
<body>
<?php
#connect to MySQL
$conn = @mysql_connect("localhost", "test", "project")
or die("Could not connect to database"

#select the database
$rs = @mysql_select_db("my_database", $conn)
or die("Could not select database")

#create SQL qery
$query = "id int(4) auto_increment,";
$query.= "name varchar(50),";
$query.= "email varchar(50),";
$query.= "comments text,";
$query.= "time timestamp(14), primary key(id)";

$sql = "create table guesbook( $query )";

#execute the query
$rs = @mysql_query ($sql)
or die("<h3>Could not create guesbook table<br> Does it already exist?</h3>");

#confirm result
echo("<h3 Created guesbook table</h3>");
?>
</body>
</html>
Quote:
Originally Posted by comments.php
<html>
<head>
<title>Sign the guestbook</title>
</head>
<body>
<?php
#html form
$form = "<form action=\"$PHP_SELF\" method=\"post\">";
$form.= "Name: <input type=\"text\" name=\"name\" ";
$form.= "size=\"50\" value=\"$name\"> <br>";
$form.= "E-Mail: <input type=\"text\" name=\"email\" ";
$form.= "Comments:<br>";
$form.= "<textarea name=\"comments\" cols=\"45\" ";
$form.= "rows=\"4\">$comments</textarea> <br>";
$form.= "input type=\"submit\" name=\"submit\" ";
$form.= "value=\"Sign\"> </form>";

#on the first opening display the form
if( !submit) { msg = $form; } else

#display a message if form is incomplete
if( !$name or !$email or !$comments)
{ $msg = "<b>Please complete all the fields</b><br><br>";
$msg.= $form; } else

#or add the data to the guesbook database

{ $conn = @mysql_connect("localhost", "test", "project")
or die("Could not connect");

#select db
$rs = @mysql_select_db("test", $conn)
or die ("Could not select database");

#create query
if($name and $comments)
{
$sql ="insert into guestbook (name, email, comments) values (\"$name\",\"$email\",\"$comments\")";
or die ("Could not execute MySQL query"); }

#confirm and view guestbook
if($rs)
{ $msg = "<h3>Thankyou, your entry has been submitted.";
$msg.= "<br><a href = \"guessbook-view.php\">";
$msg.= "View guesbook</a></h3>"; }
}

#write page
echo($msg);
?>
</body>
</html>
Quote:
Originally Posted by view-guestbook.php
<html>
<head>
<title>Sign the guestbook</title>
</head>
<body>
<?php
#html form
$form = "<form action=\"$PHP_SELF\" method=\"post\">";
$form.= "Name: <input type=\"text\" name=\"name\" ";
$form.= "size=\"50\" value=\"$name\"> <br>";
$form.= "E-Mail: <input type=\"text\" name=\"email\" ";
$form.= "Comments:<br>";
$form.= "<textarea name=\"comments\" cols=\"45\" ";
$form.= "rows=\"4\">$comments</textarea> <br>";
$form.= "input type=\"submit\" name=\"submit\" ";
$form.= "value=\"Sign\"> </form>";

#on the first opening display the form
if( !submit) { msg = $form; } else

#display a message if form is incomplete
if( !$name or !$email or !$comments)
{ $msg = "<b>Please complete all the fields</b><br><br>";
$msg.= $form; } else

#or add the data to the guesbook database

{ $conn = @mysql_connect("localhost", "test", "project")
or die("Could not connect");

#select db
$rs = @mysql_select_db("test", $conn)
or die ("Could not select database");

#create query
if($name and $comments)
{
$sql ="insert into guestbook (name, email, comments) values (\"$name\",\"$email\",\"$comments\")";
or die ("Could not execute MySQL query"); }

#confirm and view guestbook
if($rs)
{ $msg = "<h3>Thankyou, your entry has been submitted.";
$msg.= "<br><a href = \"guessbook-view.php\">";
$msg.= "View guesbook</a></h3>"; }
}

#write page
echo($msg);
?>
</body>
</html>
If you see any errors please do post and I will try to fix them, I dont believe there are any though
   
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Points Per Thread View: 0.1
Points Per Thread: 15.0
Points Per Reply: 5.0



Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 ©2007, Crawlability, Inc.