469,645 Members | 1,176 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

What stupid mistake have I done now?

142 100+

When I press sign(submit) - It looks like something is wrong and the code does not want to insert the info into my SQL...I get the error message "could not query.." that I type in under "#create the sql query" I went trough the book I got the script from and check to see that all of the spaces and letter is exactly as it should be..I am still learning php and figure I made a stupid mistake that problem someone that is fluent in PHP will pick up directly.


$self = $_SERVER['PHP_SELF'];
$name = $_POST['name'];
$email = $_POST ['email'];
$comments = $_POST ['comments'];
$submit = $_POST ['submit'];

# the html form
$form = "<form action=\"$self\" method=\"post\">";
$form.= "Name: <input type=\"text\" name=\"name\" ";
$form.= "size=\"50\" value=\"$name\"> <br>";
$form.= "Email: <input type=\"text\" name=\"email\" ";
$form.= "size=\"50\" value=\"$email\"> <br>";
$form.= "Comments:<br>";
$form.= "<textarea name=\"comments\" cols=\"45\" ";
$form.= "rows=\"4\">$comments</textarea> <br>";
$form.= "<input type=\"submit\" name=\"submit\" ";
$form.= "value=\"Sign\"> </from>";

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

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

#or add the from data to the guestbook database table
else #otherwise connect to mysql
{ $conn = @mysql_connect( "localhost", "webandwe_webandwe", "mysql" )
or die ( "could not connect to database" );

#select the database
$rs = @mysql_select_db( "webandwe_contact", $conn)
or die ("could not select database");

#create the sql query
if( $name and $comments )
$sql ="insert into guestbook (name, e-mail, comments)
$rs = @mysql_query( $sql, $conn )
or die ( "could not execute SQL query" ); }

#confirm entery and display
if ($rs)
{ $msg = "<h3>thank you - your entry has been saved.";
$msg.= "<br><a href = \"guestbook-view.php\">";
$msg.= "View my guestbook</a></h3>"; }
#write the page
echo ( $msg );
Mar 14 '07 #1
0 878

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

15 posts views Thread by news | last post: by
6 posts views Thread by Materialised | last post: by
121 posts views Thread by typingcat | last post: by
140 posts views Thread by Oliver Brausch | last post: by
8 posts views Thread by Michael | last post: by
22 posts views Thread by nick | last post: by
25 posts views Thread by Cromulent | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.