ddiddy Posted November 18, 2011 Share Posted November 18, 2011 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.. Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 18, 2011 Share Posted November 18, 2011 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. Quote Link to comment Share on other sites More sharing options...
ddiddy Posted November 19, 2011 Author Share Posted November 19, 2011 I get this error when i click the submit button from the form ( i didn't even try to load the php file,that is not the point). I also tried with if(isset($_POST['numar'])) and it appears as it is never set. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 19, 2011 Share Posted November 19, 2011 Post the current code. Quote Link to comment Share on other sites More sharing options...
ddiddy Posted November 19, 2011 Author Share Posted November 19, 2011 I just fixed it , I had a space after "post" in : method="post " ..silly mistake,but I didn't notice. Thanks anyway. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 19, 2011 Share Posted November 19, 2011 OK. Mark the thread solved with the "Topic Solved" button below, please. Quote Link to comment 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.