Guest Book

By F*U*R*B*Y* on Jan 29, 2006

this is the better guest book, it wouldn't allow me to edit cos i had to edit to much lol well here it is below, same deal
2 files,
1) process.php
2)index.php

//process.php starts here
<?
$username="username";
$password="password";
$database="your_database";

$first=$_POST['first'];
$last=$_POST['last'];
$email=$_POST['email'];
$web=$_POST['web'];
$comment=$_POST['comment'];

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO guestbook VALUES ('','$first','$last','$email','$web','$comment')";
mysql_query($query);

mysql_close();
?>
//End of Process.php
//start of index.php
<html>
<head>
<title>Guest Book</title>
</head>
<body>
<form action="process.php" method="post">
First Name: <input type="text" name="first"><br>
Last Name: <input type="text" name="last"><br>
E-mail: <input type="text" name="email"><br>
Web: <input type="text" name="web"><br>
Comments: <textarea rows="6" name="comment" cols="27"></textarea>
<input type="Submit">
</form>
</body>
</html>
//end of index.php
//start of view.php
<?

$username="username";
$password="password";
$database="your_database";
mysql_connect(localhost,$username,$password);
mysql_select_db($database) or die( "Unable to select database");

$row1 = mysql_query("SELECT * FROM guestbook")
while($row=mysql_fetch_array($row1)) {
echo "$row[first_name] $row[last_name] Said<br><hr>";
echo "$row[comments]<br><hr>";
echo "You can view $row[first_name]'s website at $row[www]";
}
?>
//end of view.php

Comments

Sign in to comment.
natar   -  Dec 21, 2010

It's not worked the insert also the view.php has an error occurred T_WHILE on line 9
that's fetch array.

 Respond  
F*U*R*B*Y*   -  Apr 02, 2007

:D updated :P

 Respond  
Hawkee   -  Feb 02, 2006

You need to create a mode that displays the information found in the database. This will require a mySQL \"select\" statement and a loop displaying the information in each row. Also, don\'t forget to include the \"create table\" query that creates your table.

 Respond  
F*U*R*B*Y*   -  Feb 01, 2006

oh ok, :$ should i need to add
echo \"$first
\";
echo \"$last
\";
echo \"$email
\";
echo \"$web
\";
echo \"$comment
\";

 Respond  
Hawkee   -  Jan 31, 2006

You need to include the \"create table\" call to mySQL because if somebody were to use this it wouldn\'t work. Also, don\'t use the values() function in mySQL. It\'s much better to use something like: set first = \'$first\', last = \'$last\' and so on. This way you can add or remove fields to the table without breaking your code. And finally, it doesn\'t look like you\'ve got a viewer that extracts the information from your db and displays it. This is incomplete.

 Respond  
F*U*R*B*Y*   -  Jan 29, 2006

Hawkee i hope this one is okay and also could you please delete the old one, cheers, and this is my first PHP code to be posted here, it is my first time scripting also so please don\'t just critize me just explain why its not good please

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.