Dear All I need you help. I would be very grateful if you can help me. When I try run the following PHP program I get the above error message. ie. Parse error: syntax error, unexpected T_VARIABLE My program is <html> <head> <title>Adding User Input to a Database</title> </head> <body> <?php if ( isset ( $fname ) && isset ($lname) && isset ($email) ) { // check user iput here ! $dberror = " "; $ret= ad_to_database ( $fname, $lname, $email, $dberror ); if ( ! $ret ) print "Error: $dberror<BR> "; else print "thank you very much "; } else { write_form() ; } function add_to_database ( $fname, $lname, $email, &$dberror ) { $user = "jmbecoo4" ; $pass = "PaZpjqRj" ; $db = "jmbecoo4_mail" ; $link = mysql_connect ( "localhost", $user , $pass ); if (! $link ) { $dberror="Couldn't connect to MySQL server "; return false ; } if ( ! mysql_select_db ( $db , $link ) ) { $dberror =mysql_error () ; return false; } $query ="INSERT INTO person (fname, lname, email ) values ('$fname', '$lanme', '$email ' ) "; if ( ! mysql_query ( $query, $link ) ) { $dberror = mysql_error () ; return false; } return true; } function write_form() { global $PHP_SELF; print "<form action=\ "$PHP_SELF \"method=\ " POST \ "> \ n"; print "Your First Name <p> \ n" ; print "<input TYPE=\ "text \ " name= \ " lname \ ">"; print "Your Last Name <p> \ n" ; print "<input TYPE=\ "varchar \ " name =\ "email \ ">"; Print "your email address<p> \ n "; print "<input TYPE=\ "submit \ " value=\ "submit ! \ " >\ n</form>\ n "; print "<input type=\"text\ " name=\ " fname\ ">"; } ?> </body> </html> Please help me to find the error. Wilfred
If I were you I'd remove your personal database pass info, regardless if you haven't gave the site link yet. Other than that I'd try placing an ; just after $query ="INSERT INTO person (fname, lname, email ) Code (markup): so that is reads $query ="INSERT INTO person (fname, lname, email ); Code (markup):
Damn, where did you learn PHP? Lots of accolades missing, and other small errors.. <html> <head> <title>Adding User Input to a Database</title> </head> <body> <?php if (isset($fname) && isset ($lname) && isset ($email)) { // check user iput here ! $dberror = " "; $ret = add_to_database ( $fname, $lname, $email, $dberror ); if (!$ret) { print "Error: $dberror<BR> "; } else { print "thank you very much "; } } else { write_form() ; } function add_to_database ( $fname, $lname, $email, &$dberror ) { $user = "xxx" ; $pass = "xxx" ; $db = "jmbecoo4_mail" ; $link = mysql_connect ( "localhost", $user , $pass ); if (! $link ) { $dberror="Couldn't connect to MySQL server "; return false ; } if (!mysql_select_db ( $db , $link)) { $dberror =mysql_error () ; return false; } $query = 'INSERT INTO person (fname, lname, email ) values ("' . mysql_real_escape_string($fname) . '", "' . mysql_real_escape_string($lanme) . '", "' . mysql_real_escape_string($email) . '")'; if ( ! mysql_query ( $query, $link ) ) { $dberror = mysql_error () ; return false; } return true; } function write_form() { global $PHP_SELF; print '<form action="' . $PHP_SELF . '" method="POST">' . "\n"; print 'Your First Name <p>' . "\n" ; print '<input TYPE="text" name="lname">'; print 'Your Last Name <p>' . "\n" ; print '<input TYPE="varchar" name="email">'; Print 'your email address<p>' . "\n"; print '<input TYPE="submit" value="submit!">' . "\n" . '</form>' . "\n"; print '<input type="text " name="fname">'; } ?> </body> </html> PHP:
Dear Friends, Thanks a lot for replying to my querry. I have sent you two private mails. Hope you will receive them. If not please mail me back. Thanks. Wilfred.
Try this code instead, but really, we are not here to do all of your work. You really should start learning PHP yourself.. <html> <head> <title>Adding User Input to a Database</title> </head> <body> <?php if (!empty($_POST['fname']) && !empty($_POST['lname']) && !empty($_POST['email'])) { $dberror = " "; $ret = add_to_database ( $_POST['fname'], $_POST['lname'], $_POST['email'], $dberror ); if (!$ret) { print "Error: $dberror<BR> "; } else { print "thank you very much "; } } else { write_form() ; } function add_to_database ( $fname, $lname, $email, &$dberror ) { $user = "xxx" ; $pass = "xxx" ; $db = "jmbecoo4_mail" ; $link = mysql_connect ( "localhost", $user , $pass ); if (! $link ) { $dberror="Couldn't connect to MySQL server "; return false ; } if (!mysql_select_db ( $db , $link)) { $dberror =mysql_error () ; return false; } $query = 'INSERT INTO person (fname, lname, email ) values ("' . mysql_real_escape_string($fname) . '", "' . mysql_real_escape_string($lanme) . '", "' . mysql_real_escape_string($email) . '")'; if ( ! mysql_query ( $query, $link ) ) { $dberror = mysql_error () ; return false; } return true; } function write_form() { global $PHP_SELF; print '<form action="' . $PHP_SELF . '" method="POST">' . "\n"; print '<p>Your First Name </p><p><input type="text " name="fname"></p>' . "\n"; print '<p>Your Last Name </p><p><input TYPE="text" name="lname"></p>' . "\n"; Print '<p>your email address</p><p><input TYPE="varchar" name="email"></p>' . "\n"; print '<p><input TYPE="submit" value="submit!"></p>' . "\n" . '</form>' . "\n"; } ?> </body> </html> PHP:
Dear Sir, I very much appreciate your kindness in sending a reply to my mail. The edited php code worked well. There was small error. I was able to corect it. Sorry if I disturbed your busy schedule. Please allow me to relate you my side of the story. I am using the book name "SAMS TEACH YOURSELF - PHP4 in 24 hours" By Matt Zandstra Published by Techmedia. What I tried to implement was the Listing 12.3 at Page 200. What I sent you in my Thread was this program. So now thanks to you I will find a better book to learn PHP than what I am using now. So Thank you again. Please pardon me for any inconveniency caused. Thanks Wilfred.
No problem I was a little harsh there. Just trying to get people to learn PHP instead of posting all their problems here However, you are learning PHP so that's a good thing. I hope you get a better book and one that is updated for PHP5. I believe there are a few posts in this forum with book recommendations. You will not learn PHP in 24 hours as your book suggests
Thanks for the prompt reply. I was little bit worried about arousing your feelings. Now I am relieved as you are happy. I will go through and find a suitable book. I hope to contact you later for any difficult problem. Thanks. Wilfred Cooray from Sri Lanka.