Conjurer Posted March 7, 2011 Share Posted March 7, 2011 I have a form that is populating fields based on a database query. I am then trying to update the database based on any changes made in the form and passed through a POST action. The problem I am having is with the block where I declare short variable names for the $_POST variables that will be passed when the user hits the submit button. For each variable declaration I get an error message like this: Encountered error: 8 in mbr_profile_updt_form.php, line 130: Undefined index: email I have tried testing the $_POST variable using the isset function but it apparently is set but empty. What would be a good way to test to see if the user has pressed the submit button before I go into the processing block that is intended to handle those values from the form? Here is where my code is at right now: if (!isset($_POST)) { throw new Exception('You have not filled the form out completely - please go back' .' and try again.'); } else { //filled in so create short variable names $email=$_POST['email']; $first_name=$_POST['first_name']; $last_name=$_POST['last_name']; Link to comment https://forums.phpfreaks.com/topic/229906-how-can-i-test-the-_post-array-to-see-if-it-is-set-by-the-form/ Share on other sites More sharing options...
jasonrichardsmith Posted March 7, 2011 Share Posted March 7, 2011 Have you tried if (!isset($_POST['email'])) Link to comment https://forums.phpfreaks.com/topic/229906-how-can-i-test-the-_post-array-to-see-if-it-is-set-by-the-form/#findComment-1184146 Share on other sites More sharing options...
Conjurer Posted March 7, 2011 Author Share Posted March 7, 2011 No, but I also stumbled on the empty() function which seems better...as in if (empty($_POST)) Link to comment https://forums.phpfreaks.com/topic/229906-how-can-i-test-the-_post-array-to-see-if-it-is-set-by-the-form/#findComment-1184205 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.