January 13, 201115 yr Hello friends, I am still new in php and i am just making a simple contact form and testing on local host but it gives error here is the code <!DOCTYPE html PUBLIC "-//W3c//DTD xhtml 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1"/> <title>Simple html form</title> <style type="text/css"> fieldset{ font-family:"Arial"; background:grey; margin:0 auto; padding:5px; width:500px; border:5px solid grey; } input.formInputText{ background:yellow; padding:2px; border:1px solid white; height:20px; font:Arial; color:#000000; } </style> </head> <body> <!--Script 2.1-form.html--> <form action="handle_form.php" method="post"> <fieldset> <legend>Enter Your information in the form below:</legend> <p><b>Name:</b><input class="formInputtext" type="text" name="name" size="20" maxlength="40"/></p> <p><b>Email Address:</b><input type="text" name="email" size="40" maxlength="60"/> </p> <p><b>gender:</b><input type="radio" name="gender" value="Male"/>Male<input type="radio" name="gender" value="F"/> Female </p> <p><b>Age:</b><select name="age"><option value="0-29">Under 30</option> <option value="0-29">Under 30</option> <option value="30-60">Between 30-60</option> <option value="60+">Over 60</option> </select></p> <p><b>Comments:</b><textarea name="comments" rows="3" cols="40"></textarea> </p> </fieldset> <div align="center"><input type="submit" name="submit" value="submit my information"/></div> </form> </body> </html> and handle_form.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.DTD"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html";charset=iso-8859-1"/> <title>Foprm feedback</title> </head> <body> <?php $name = $_REQUEST['name']; $email = $REQUEST['email']; $comments = $REQUEST['comments']; echo "<p> Thank you,<b>$name</b>,for the following comments</br> <tt>$comments</tt></p>" <p>We will reply to you at <i> $email ,</i>.</p>\n"; ?> </body> </html> error Parse error: parse error in C:\wamp\www\html\handle_form.php on line 15 i am following larry ullmans book
January 13, 201115 yr echo "<p> Thank you,<b>$name</b>,for the following comments</br> <tt>$comments</tt></p>" <p>We will reply to you at <i> $email ,</i>.</p>\n"; ?> You should see that the " after the </p> isn't meant to be there. Remove it and it should work
January 13, 201115 yr Author echo "<p> Thank you,<b>$name</b>,for the following comments</br> <tt>$comments</tt></p>" <p>We will reply to you at <i> $email ,</i>.</p>\n"; ?> You should see that the " after the </p> isn't meant to be there. Remove it and it should work i cahnged it but still shows error <?php $name = $_REQUEST['name']; $email = $REQUEST['email']; $comments = $REQUEST['comments']; echo "<p> Thank you,<b>$name</b>,for the following comments</br> <tt>$comments</tt></p>" <p>We will reply to you at <i> $email ,</i>.\n"; ?> but i dont know why in the book the code is wrong
January 13, 201115 yr In the code you've just posted back you still have the " there <?php $name = $_REQUEST['name']; $email = $REQUEST['email']; $comments = $REQUEST['comments']; echo "<p> Thank you,<b>$name</b>,for the following comments</br> <tt>$comments</tt></p> <p>We will reply to you at <i> $email ,</i>.\n"; ?> is how it should be
January 13, 201115 yr Author In the code you've just posted back you still have the " there <?php $name = $_REQUEST['name']; $email = $REQUEST['email']; $comments = $REQUEST['comments']; echo "<p> Thank you,<b>$name</b>,for the following comments</br> <tt>$comments</tt></p> <p>We will reply to you at <i> $email ,</i>.\n"; ?> is how it should be Notice: Undefined variable: REQUEST in C:\wamp\www\html\handle_form.php on line 13 Notice: Undefined variable: REQUEST in C:\wamp\www\html\handle_form.php on line 14 Thank you,ddd,for the following comments We will reply to you at ,.
January 13, 201115 yr Oh dear, you shouldn't be using REQUEST, you should be using $_POST How old exactly is the book you are reading?
January 13, 201115 yr Author Also note for lines 13/14 you have $REQUEST (missing the underscore) ah got it still have to practice alot
January 13, 201115 yr Author Oh dear, you shouldn't be using REQUEST, you should be using $_POST How old exactly is the book you are reading? its php 6 and mysql 5 by larry ullman
January 13, 201115 yr I see...nobody uses $_REQUEST any more, and haven't for a while as far as I know. You should know the request you are receiving, for example your form is POSTing the data, so you use $_POST. you aren't going to be using another form somewhere else with the exact same setup to send the form via $_GET It worries me people are learning this from what is considered a recent book
January 13, 201115 yr its php 6 and mysql 5 by larry ullman Regardless, if they are teaching u to use request for form input, when u should be using post then i'd suggest u get another book cause there teaching u wrong
January 13, 201115 yr Author Regardless, if they are teaching u to use request for form input, when u should be using post then i'd suggest u get another book cause there teaching u wrong so i feel this tutorial is better
January 13, 201115 yr so i feel this tutorial is better Yes it is better however i do wanna point out a few things, get in the habit of writing post variables like this $name = (isset($_POST['name'])) ? $_POST['name'] : ''; insted of $name = $_POST['name']; this prevents undefined index errors.
January 13, 201115 yr Author Yes it is better however i do wanna point out a few things, get in the habit of writing post variables like this $name = (isset($_POST['name'])) ? $_POST['name'] : ''; insted of $name = $_POST['name']; this prevents undefined index errors. can u explain it a bit more with example as it will be more clear to me
January 14, 201115 yr can u explain it a bit more with example as it will be more clear to me Well best way to under stand it is to turn on error reporting by putting this at the top of ur page ERROR_REPORTING(E_ALL); and then a variable written like this $name = $_POST['name']; it will result in an error because the variable contains no data yet but also does not have a default value so thats what this is saying. $name = (isset($_POST['name'])) ? $_POST['name'] : FALSE; its saying if post isset--aka contains data then get that data otherwise result to false which is its default or u can do '' insted of putting false
Create an account or sign in to comment