sahlahmin Posted October 15, 2010 Share Posted October 15, 2010 Not sure why the PHP variables in the code below aren't interpreting the values that they should be receiving from the HTML form. HTML form <form action="handle_form.php" method="post"> <fieldset><legend>Enter your information in the form below</legend> <p><b>Name:</b> <input 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="M" /> 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="30-60">Between 30 and 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="Sumbit My Information" /></div> </form> PHP handle_form <?php #Script 2.2 handle_form.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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/215914-handling-an-html-form/ Share on other sites More sharing options...
Pikachu2000 Posted October 15, 2010 Share Posted October 15, 2010 What actually is happening, then? Anything? Nothing? Any error messages? Quote Link to comment https://forums.phpfreaks.com/topic/215914-handling-an-html-form/#findComment-1122385 Share on other sites More sharing options...
sahlahmin Posted October 15, 2010 Author Share Posted October 15, 2010 when submitting information from the HTML form , the echo function is printing part of the message literally, and then just not the rest, like this... Thank you, $name, for the following comments: $comments We will reply to you at $email. "; ?> Quote Link to comment https://forums.phpfreaks.com/topic/215914-handling-an-html-form/#findComment-1122388 Share on other sites More sharing options...
chintansshah Posted October 15, 2010 Share Posted October 15, 2010 Please replace with below code 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>"; I used string concatenation. Quote Link to comment https://forums.phpfreaks.com/topic/215914-handling-an-html-form/#findComment-1122441 Share on other sites More sharing options...
Pikachu2000 Posted October 15, 2010 Share Posted October 15, 2010 The concatenated code is functionally no different from what is posted in the OP. Concatenating it like that is pointless. If the code posted in the OP directly copied/pasted from the script? If so, make a new file, and put the following in it, pick a name and save it, then call it into your browser. <?php phpinfo(); ?> If it isn't a direct copy, please copy/paste the actual the code here. Quote Link to comment https://forums.phpfreaks.com/topic/215914-handling-an-html-form/#findComment-1122465 Share on other sites More sharing options...
sahlahmin Posted October 15, 2010 Author Share Posted October 15, 2010 where would phpinfo(); fit within the php tags of the code that i posted? can you post an example of what your talking about? I'm pretty new to php. Quote Link to comment https://forums.phpfreaks.com/topic/215914-handling-an-html-form/#findComment-1122559 Share on other sites More sharing options...
Pikachu2000 Posted October 15, 2010 Share Posted October 15, 2010 It doesn't go in the existing file, it goes in a new file. Save it as phpinfo.php, then call it into your browser as you would any other php script. Quote Link to comment https://forums.phpfreaks.com/topic/215914-handling-an-html-form/#findComment-1122563 Share on other sites More sharing options...
phpfreak Posted October 16, 2010 Share Posted October 16, 2010 Also try using $_POST instead of $_REQUEST Quote Link to comment https://forums.phpfreaks.com/topic/215914-handling-an-html-form/#findComment-1122631 Share on other sites More sharing options...
kenrbnsn Posted October 16, 2010 Share Posted October 16, 2010 How are you invoking the HTML file which contains the form? Ken Quote Link to comment https://forums.phpfreaks.com/topic/215914-handling-an-html-form/#findComment-1122634 Share on other sites More sharing options...
sahlahmin Posted October 17, 2010 Author Share Posted October 17, 2010 kenrbnson, I think this is the line your talking about... <form action="handle_form.php" method="post"> its the only line in either document that links the two scripts together, other then them being in the same folder. phpfreaks, I tried $_POST, same results Quote Link to comment https://forums.phpfreaks.com/topic/215914-handling-an-html-form/#findComment-1123056 Share on other sites More sharing options...
sahlahmin Posted October 17, 2010 Author Share Posted October 17, 2010 Ok guys, I figured out what the problem was. I guess I wasn't previewing the page through a URL, and using the preview in Firefox method in Dreamweaver. Thanks again everyone for your time. Quote Link to comment https://forums.phpfreaks.com/topic/215914-handling-an-html-form/#findComment-1123060 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.