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