Helping ordinary people create extraordinary websites!

Go Back   Web Development Forum > Website Management > Scripts and Software
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-25-2008, 10:44 AM
Junior Member
 
Join Date: Aug 2008
Posts: 2
Default Creating guestbook problems

Hi,

I'm trying to create a simple guestbook following a tutorial. I stucked at some point.

So this is where I am; i've created the form and some php code as well as the database table

PHP Code:
<?php
    
require($_SERVER["DOCUMENT_ROOT"]."/guest/config/db_config.php");
    
$connection = @mysql_connect($db_host$db_user$db_password) or die ("error connection");
    
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"]; //see if there is an email element
      
$comment $_POST["txt_comment"];
      
$date time(); //returns the date in seconds    
      
      //Now, have to set up mysql query
      
$query "INSERT INTO guestbook (ID, name, email, comment, date_auto) VALUES (NULL '$name', '$email', '$comment', '$date')";
      
      
//Now, we have to run the actual query
      
mysql_query($query$connection) or die (mysql_error()); //save it to the database or send an error
        
    
}
?>

<html>
  <head>
    <title>Guestbook</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">&nbsp;
    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>
This is the table i1ve created:

Code:
CREATE TABLE IF NOT EXISTS `guestbook` (
  `ID` int(10) unsigned NOT NULL auto_increment,
  `name` varchar(64) default NULL,
  `email` varchar(64) default NULL,
  `comment` text,
  `date_auto` int(10) unsigned default NULL,
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
The form appears in the browser but when I try to send a message i get this sql error:

Code:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''tom', 'dtommy79@yahoo.com', 'test message', '1219671750')' at line 1
I don't really know what it means
Any help is appreciated
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 08-27-2008, 03:11 AM
ryanhellyer's Avatar
Super Moderator
 
Join Date: Dec 2007
Posts: 708
Default

Sorry, this is looking a little beyond my meagre programming abilities. Hopefully someone else will be able to help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-27-2008, 04:10 AM
Junior Member
 
Join Date: Aug 2008
Posts: 2
Default

Never mind. I found the problem.
There was a missing comma after NULL in the insert query.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-31-2008, 06:14 AM
ryanhellyer's Avatar
Super Moderator
 
Join Date: Dec 2007
Posts: 708
Default

Glad to hear you got it working
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
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



All times are GMT -5. The time now is 11:31 PM.


Website Design by Ducani Media Group
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.