What is possibly wrong with following script that caused it to scream ?

<!DOCTYPE html>
   function formSubmit()
<form id="form1" action="test.php" method="POST">
 Name: <input type="text" name="name" ><br/>
 <input type="button" onclick="formSubmit()" value="Submit" />
echo "<br> Your name is $name1 . Thanks for using our system.";

Following is error snap:


Thank You.

4 Years
Discussion Span
Last Post by JorgeM

The $_POST array doesn't contain a name element. The reason is in that the name input field has not been submitted yet. Include a check such as:

if(isset($_POST['name']) && !empty($_POST['name'])) {
    echo "<br> Your name is $name1 . Thanks for using our system.";

Even better would be to check for form submission:

if(isset($_POST['submit']) && isset($_POST['name']) && !empty($_POST['name'])) {
    echo "<br> Your name is $name1 . Thanks for using our system.";

In order this to work you should add a name attribute to the submit button:

<input type="button" onclick="formSubmit()" name="submit" value="Submit" />

Edited by broj1


I'm not a PHP developer..I'm sure you'll have other members provide feedback.. but it seems to me that you only have one page and I guess that's Ok, but when this page loads, you are trying to assign a value which is probably undefined at the moment to $name1.


After the form is submitted to the same page, I would imaging that $_POST['name'] would contain a value. Until the post happens, there is no value.

Does this seem correct?

[EDIT] -- looks like broj1 posted a response while I was typing mine. Thanks for validating what I was thinking..

Edited by JorgeM

Votes + Comments
Nice explanation

thanx fellas JorgeM and broj1 . . . . that helped me understand this topic a lot. Moving on to next problem hope i will get your help.

Thanx a ton :-)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.