Jump to content

Problem sending data from a html form to a php file


ddiddy

Recommended Posts

So here is my code:

//form.html

<form action="http://localhost/lab3/index.php" method="post " >

<input type="text" name="numar" value=""><br>

        <input type="submit" name="submitButton" value="Submit">

</form>

 

 

//and in index.php ,which is in the specified folder if I write :

if($_POST['numar']!="")

$m=$_POST['numar'];

 

//then I get an error saying Undefined index: numar

 

I really read a lot about forms and saw examples , but I can't figure out what's wrong. If you have any ideas..

I assume you are getting that error when you FIRST load the page and not when you actually submit the form. That is because of your if() condition

if($_POST['numar']!="")

 

The PHP parser is throwing a warning because it can't test $_POST['numar'] because it doesn't exist (if you haven't POSTed the form). Instead you should use isset()

if(isset($_POST['numar']))

 

Although you should probably also run trim on the value and test that it's not empty in the validation logic.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.