jimfog Posted September 20, 2011 Share Posted September 20, 2011 I want to insert some data to the database. This data comes from an html form which asks for a name and a phone. here is the form: <form action="Proccess.php" method="post"> <table border="0"> <tr> <td>Όνομα</td> <td><input type="text" name="Name" maxlength="45" size="35" /></td> </tr> <tr> <td>Tηλέφωνο</td> <td><input type="text" name="Phone" maxlength="45" size="35" /></td> </tr> <tr> <td><input type="submit" value="send" maxlength="25" size="15" /></td> </tr> </table> </form>' ?> In the proccess.php file i have entered an if statement to check if the user actually entered his details: if(!$name||!$phone){echo 'You have not entered all the required info';exit;} Nonetheless, even if the user enters all his/her detail i get 'You have not entered all the required info'. So, despite the user entering his details, PHP treats the situation as though he has not. What can be wrong in the above situation? Link to comment Share on other sites More sharing options...
boen_robot Posted September 20, 2011 Share Posted September 20, 2011 You need to use $_POST['name'] and $_POST['phone'], not just $name and $phone.Furthermore, you should use isset() instead, like: if (!isset($_POST['name']) || !isset($_POST['phone'])) { echo 'You have not entered all the required info'; exit;} Link to comment Share on other sites More sharing options...
thescientist Posted September 20, 2011 Share Posted September 20, 2011 as said above, you actually need to look inside the $_POST array.http://www.w3schools.com/php/php_forms.asp Link to comment Share on other sites More sharing options...
justsomeguy Posted September 20, 2011 Share Posted September 20, 2011 Furthermore, you should use isset() instead, like:That should be empty instead of isset, they'll always be set if the form was submitted. Link to comment Share on other sites More sharing options...
jimfog Posted September 21, 2011 Author Share Posted September 21, 2011 Unfortunately it does not work. I cannot understand why. here is the code, the new one: if (!isset($_POST['name']) || !isset($_POST['phone'])){echo 'Κάποια στοιχεία λείπουν';exit;} I have also tried without the isset directive. I am wondering if the problem lies in the database and in the option i have set for the specific table/fields. Link to comment Share on other sites More sharing options...
thescientist Posted September 21, 2011 Share Posted September 21, 2011 You should be aware that the name of the form elements is case sensitive with respect to how they will show up in the POST array. Compare the two. In the form you have the first letter capitalized, but not in your PHP script. Link to comment Share on other sites More sharing options...
jimfog Posted September 21, 2011 Author Share Posted September 21, 2011 Yes, this time the result was the desired one. Thanks. I have another problem now but this is a different post-if i do not solve on my own. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.