|
-
Oct 22nd, 2008, 10:05 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Help again sorry
Can anyone tell me why this code isnt showing me the form on my website click the link and youll see what i mean.?
http://www.webspace4rent.biz/guestbook/sign.php
below is the code.
PHP Code:
<html><head><title>Sign the guestbook</title></head>
<body>
<?php $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\"> </form>";
#on first opening display the form
if( !$submit) { $msg = $form; }
#or redisplay a message and the form if incomplete
else if( !$name or !$email or !$comments; }
{ $msg = "<b>PLease complete all the fields</b><br><br>";
$msg.= $form; }
#or add the form data to the guestbook database table
else #otherwise connect to MySQL
{ $conn = @mysql_connect( "localhost", "webspace_guest", "brodie" )
or die( "Could not connect to database" );
#select the database
$rs = @mysql_select_db( "webspace_guest", $conn )
or die ( " Could not select database" );
#create the SQL query
if( $name and $comments )
{
$sql ="insert into guestbook (name email, comments)
value(\$name\",\"$email\",\"$comments\")";
$rs = @mysql_query( $sql $conn )
or die ("Could not execute SQL query");}
#confirm entry and display a link to view guestbook
if($rs)
{ $msg = "<h3>Thank you - your entry has been saved.";
$msg = "<br><a href = \"view.php\">";
$msg = "View My Guestbook</a></h3>"; }
}
#write the page
echo( $msg );
?>
</body></html>
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Oct 22nd, 2008, 10:14 AM
#2
Re: Help again sorry
Double check your braces.
Just with a quick look I noticed that
PHP Code:
else if( !$name or !$email or !$comments; }
should be
PHP Code:
else if( !$name or !$email or !$comments )
You also missed a comma on
PHP Code:
$rs = @mysql_query( $sql $conn )
it should be
PHP Code:
$rs = @mysql_query( $sql, $conn )
After that, it should load.
-
Oct 22nd, 2008, 10:24 AM
#3
Thread Starter
Frenzied Member
Re: Help again sorry
I have got it to show now when i fill out the form and click submit it says PLease complete all the fields but all fields have been typed in?
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Oct 22nd, 2008, 10:36 AM
#4
Re: Help again sorry
Can you post your updated code, please?
Just the basics of
PHP Code:
<html><head><title>Sign the guestbook</title></head> <body> <?php $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\"> </form>";
#on first opening display the form
if( !$name or !$email or !$comments )
{ $msg = "<b>PLease complete all the fields</b><br><br>"; $msg.= $form; } else { $msg = $form ;}
echo( $msg ); echo ("Name: " . $name . "<br />"); echo ("Email: " . $email . "<br />"); echo ("Comments: " . $comments . "<br />"); ?> </body></html>
Seems to work fine.
-
Oct 22nd, 2008, 10:42 AM
#5
Thread Starter
Frenzied Member
Re: Help again sorry
This is the code but it says when i try to submit the fields it says could not execute the query.
Code:
<html><head><title>Sign the guestbook</title></head>
<body>
<?php $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\"> </form>";
#on first opening display the form
if( !$submit) { $msg = $form; }
#or redisplay a message and the form if incomplete
else if( !$name or !$email or !$comments )
{ $msg = "<b>PLease complete all the fields</b><br><br>";
$msg.= $form; }
#or add the form data to the guestbook database table
else #otherwise connect to MySQL
{ $conn = @mysql_connect( "localhost", "webspace_guest", "brodie" )
or die( "Could not connect to database" );
#select the database
$rs = @mysql_select_db( "webspace_guest", $conn )
or die ( " Could not select database" );
#create the SQL query
if( $name and $comments )
{
$sql ="insert into guestbook (name, email, comments)
values(\$name\",\"$email\",\"$comments\")";
$rs = @mysql_query( $sql, $conn )
or die ("Could not execute SQL query");}
#confirm entry and display a link to view guestbook
if($rs)
{ $msg = "<h3>Thank you - your entry has been saved.";
$msg = "<br><a href = \"view.php\">";
$msg = "View My Guestbook</a></h3>"; }
}
#write the page
echo( $msg );
?>
</body></html>
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Oct 22nd, 2008, 10:45 AM
#6
Re: Help again sorry
If that is the only problem, you're missing a quote here:
PHP Code:
$sql ="insert into guestbook (name, email, comments)
values(\$name\",\"$email\",\"$comments\")";
should be
PHP Code:
$sql ="insert into guestbook (name, email, comments)
values(\"$name\",\"$email\",\"$comments\")";
-
Oct 22nd, 2008, 12:41 PM
#7
Re: Help again sorry
Jamie, I suggest you buy yourself a book and learn how to code using PHP; instead of asking us to solve your problems for you.
-
Oct 22nd, 2008, 12:48 PM
#8
Re: Help again sorry
 Originally Posted by visualAd
Jamie, I suggest you buy yourself a book and learn how to code using PHP; instead of asking us to solve your problems for you.
Not necessarily a coding book, but reading up on popular debugging practices would definitely help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|