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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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