Jump to content

Problem in PHP Guestbook


indianlibra

Recommended Posts

I created the guestbook's table in my database

 

all things looks perfectly ok, but i don't know where's the problem

 

this script is not completed

 

but its enough to insert the values in the table

 

i don't have any idea where i maked mistake

 

i wasted my 2 hour just for searching the its problem

 

can u find the it

 

<?php
require($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php");
$connection = @mysql_connect($db_host, $db_user, $db_password) or die("error connecting"); 
mysql_select_db($db_name, $connection);

$name = $_POST["txt_name"];
$len = strlen($name);
//only write to database if there's a name
if($len>0)
{
	$email = $_POST["txt_email"];
	$comment = $_POST["txt_comment"];
	$date = time();

	$query = "INSERT INTO guestbook (autoID, name, email, comment, date_auto)
			  VALUES(NULL, '$name', '$email', '$comment', '$date')";

	mysql_query($query, $connection) or die(mysql_error());
}
?>

<html>
<head>
<title>Gestbook</title>
</head>
<body>
<center>
<form action="<?php echo $_SERVER[php_SELF]; ?>" method="POST">
<font face="arial" size="1">
	Name: <input type="text" name="txt_name">;
	Email: <input type="text" name="txt_email"><br><br>
	Comment: <br>
	<textarea style="width: 75%" rows="10" name="txt_comment"></textarea>
	<center><input type="submit" value="Submit"></center>
</font>
</form>

</center>
</body>
</html>

 

Image 1

i395992_phpguestbook.gif

 

Image 2

i396007_phpconfigfile.gif

 

 

Image 3

i396011_mysqlguestbooktable.gif

 

 

Image 4

i396013_localhostbrowserviewofguestbookfile.gif

 

 

Image 5

 

i396014_localhostbrowserviewofguestbookfileafterputtingvalues.gif

Link to comment
https://forums.phpfreaks.com/topic/44664-problem-in-php-guestbook/
Share on other sites

First of all:

	$connection = @mysql_connect

should be:

	$connection = mysql_connect

 

and

<form action="<?php echo $_SERVER[php_SELF]; ?>"

should be:

<form action="<?php echo $_SERVER['PHP_SELF']; ?>"

 

it worked

 

i can't believe i wasted my time on this silly mistake

 

i just want to slap myself

 

buy thanks papaface

How does the output looks?

 

are you trying to ask about the output in browser or in table

 

well i didn't completed the script yet

 

So i can only show you the output in the database table

 

After entering the values in the guestbook's fields it automatically stores in the table

 

Data In Table

i396153_output.gif

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.