Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP basic form error

Featured Replies

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

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

 

  • 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";
 ?>

:search:

 

but i dont know why in the book the code is wrong :bangb:

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

 

  • 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 ,.

Oh dear, you shouldn't be using REQUEST, you should be using $_POST

How old exactly is the book you are reading?

  • 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 :mellow:

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 :unsure::blink:

its php 6 and mysql 5 by larry ullman :mellow:

 

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

  • 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

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.

  • 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 :rolleyes:

can u explain it a bit more with example as it will be more clear to me :rolleyes:

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.