I'm writing a very simple script for a guestbook, pretty much just playing and experminenting with mysql/php.
The guestbook displays the info from the db fine, but to update it I have the following:
gbooksign.php
<form action="gbooksignok.php" method="post">
<input type="text" name="name" size="50" value="name"><br>
<input type="text" name="email" size="50" value="email"><br>
<input type="text" name="site" size="50" value="website"><br>
<textarea name="comments" cols="50" rows="4">comments?</textarea><br><br>
<input type="submit" name="submit" value="[ take me away ]">
</form>
gbooksignok.php
<?php
include("dbconnect.php");
?>
<?php
# check to ensure name and comments have been filled in
if( $name == name or $comments == comments )
{
$msg = "<b>You have not completed all the fields required...</b><br>";
$msg.= "<a href=\"gbooksign.php\">Go back...</a>";
}
else
{
$sql = "insert into gbook (name,email,site,comments) values (\"$name\",\"$email\",\"$site\",\"$comments\")";
$rs = @mysql_query($sql)
or die("Could not execute query");
}
if($rs)
{
$msg = "Thank you for signing the guestbook, your comment was added.<br>";
$msg.= "<a href=\"gbook.php\">Return to guestbook</a>";
}
echo ($msg);
?>
As it stands, the script updates the db but with blank info. Equally the check to make sure name and comments have been filled out doesn't do squat. This all tells me that the variables haven't gotten through to the gbooksignok.php script 🙂
Now I know I'm most likely going to be using $_POST, I figured that much out, but how exactly? I've tried defining $name, $email, $site and $comments immediately before running the name/comments check as follows:
<?php
$name = $_POST["name"]
$email = $_POST["email"]
$site = $_POST["site"]
$comments = $_POST["comments"]
# check to ensure name and comments have been filled in
if( $name == name or $comments == comments )
{
$msg = "<b>You have not completed all the fields required...</b><br>";
$msg.= "<a href=\"gbooksign.php\">Go back...</a>";
}
(etc......)
But that threw up an error... as did going through and replacing every instance of $name, $email, $comments and $site with the $_POST["whatever"] alternative....
I have to admit I'm somewhat stumped, and reading a number of tutorials and Manual pages hasen't really helped.