cyberRobot Posted January 28, 2011 Share Posted January 28, 2011 I recently had a customer say that one of my forms isn't working. For some reason the ID number is getting lost when she submits the form. The form code looks like: ... print "<form method='post' name='form' action='update.php'>"; ... print "<input type='hidden' name='id' value=\"$id\" />"; print "<input type='submit' name='submit' value=\"Save Session\" />"; print "</form>"; ... And the PHP code that gets executed looks like: ... //GET SESSION ID if(isset($_GET['id'])) { //ID from HTML link, before updates have been made $id = $_GET['id']; } elseif(isset($_POST['id'])) { //ID from form, after updates have been made $id = $_POST['id']; } else { $id = ''; } //IF SESSION ID IS VALID if(preg_match("/^\d+$/", $id)) { ... //ELSE, INVALID ID } else { $msg = "<span class='errorText'>Session ID not found or invalid.</span>"; } ... For some reason she usually gets the "Session ID not found..." error when submitting the form. Do you see any problems with the above code? Note that she has been able to sucessfully use the form before (in the same day); we have nearly 1,800 records submitted using these forms; and I am unable to duplicate the issue. So I'm at a loss on what to do next. Also, she talked with her IT person about the form. The IT person was able to submit data on his computer. So he reset her Internet options which seemed to fix the problem on her end temporarily. Note that she is using IE 7. She also said that she doesn't have access to any other browsers. I'm tempted to chalk this up as a personal computer issue, but wanted to get your input first. Quote Link to comment https://forums.phpfreaks.com/topic/225984-losing-_get-and-_post-data/ Share on other sites More sharing options...
l4nc3r Posted January 28, 2011 Share Posted January 28, 2011 Why are you worrying about passing session id's when they can easily be carried with cookies? Quote Link to comment https://forums.phpfreaks.com/topic/225984-losing-_get-and-_post-data/#findComment-1166689 Share on other sites More sharing options...
blew Posted January 28, 2011 Share Posted January 28, 2011 print "<input type='hidden' name='id' value=\"$id\" />"; change it to print "<input type='hidden' name='id' value=\"<?php echo $id; ?>\" />"; this might work Quote Link to comment https://forums.phpfreaks.com/topic/225984-losing-_get-and-_post-data/#findComment-1166755 Share on other sites More sharing options...
cyberRobot Posted January 28, 2011 Author Share Posted January 28, 2011 Why are you worrying about passing session id's when they can easily be carried with cookies? The form mentioned above is to edit training session information. It's used to pull the record for editing by this form only. Quote Link to comment https://forums.phpfreaks.com/topic/225984-losing-_get-and-_post-data/#findComment-1166756 Share on other sites More sharing options...
cyberRobot Posted January 28, 2011 Author Share Posted January 28, 2011 Quick update: I asked the customer to look at the source code and it turns out that the hidden form field is being populated. So somehow that data is being lost after the submit button is clicked. Quote Link to comment https://forums.phpfreaks.com/topic/225984-losing-_get-and-_post-data/#findComment-1166757 Share on other sites More sharing options...
Pikachu2000 Posted January 28, 2011 Share Posted January 28, 2011 print "<input type='hidden' name='id' value=\"$id\" />"; change it to print "<input type='hidden' name='id' value=\"<?php echo $id; ?>\" />"; this might work No, that won't work. By virtue of the fact that a print() has been issued, we can assume that we are already inside the opening <?php tag, therefore there is no reason to reissue a <?php tag, nor is there reason to use an echo within a print(). What you need to do is view the html source in the first script to make sure the value is actually echoed into the to the hidden field's name= attribute, then print_r($_POST) to see if the value is in the post array. EDIT: Just saw the above note about the value being present . . . Quote Link to comment https://forums.phpfreaks.com/topic/225984-losing-_get-and-_post-data/#findComment-1166759 Share on other sites More sharing options...
blew Posted January 29, 2011 Share Posted January 29, 2011 print "<input type='hidden' name='id' value=\"$id\" />"; change it to print "<input type='hidden' name='id' value=\"<?php echo $id; ?>\" />"; this might work No, that won't work. By virtue of the fact that a print() has been issued, we can assume that we are already inside the opening <?php tag, therefore there is no reason to reissue a <?php tag, nor is there reason to use an echo within a print(). What you need to do is view the html source in the first script to make sure the value is actually echoed into the to the hidden field's name= attribute, then print_r($_POST) to see if the value is in the post array. EDIT: Just saw the above note about the value being present . . . oh well, but in my see, he used print just to show the "hidden button", just like he did to the others parts of the form... i always use that way <?php echo $id; ?> and it always worked fine to me! Quote Link to comment https://forums.phpfreaks.com/topic/225984-losing-_get-and-_post-data/#findComment-1166805 Share on other sites More sharing options...
lazylodr Posted January 29, 2011 Share Posted January 29, 2011 Do you have a different <input> tag in your form with the name "id"? Also, I wonder why you are checking for $_GET['id'] when your form's method is clearly post? Try print_r($_POST); on a submission and see what comes back. Quote Link to comment https://forums.phpfreaks.com/topic/225984-losing-_get-and-_post-data/#findComment-1166845 Share on other sites More sharing options...
cyberRobot Posted January 29, 2011 Author Share Posted January 29, 2011 Do you have a different <input> tag in your form with the name "id"? Nope Also, I wonder why you are checking for $_GET['id'] when your form's method is clearly post? The script uses both $_GET and $_POST. To get to the edit form, the user clicks a link with an ID variable ($_GET). Then when they submit the form the ID is sent back to the page using $_POST. Try print_r($_POST); on a submission and see what comes back. The customer said she would try filling out the form on her home computer this weekend. If the form still doesn't work I may try the solution. I would need to have the customer let me know if the variable gets displayed. This would be so much easier if I could duplicate the issue, but the form works fine for me in multiple browsers and multiple computers. Quote Link to comment https://forums.phpfreaks.com/topic/225984-losing-_get-and-_post-data/#findComment-1166866 Share on other sites More sharing options...
cyberRobot Posted January 31, 2011 Author Share Posted January 31, 2011 For what it's worth, the customer was able to enter the rest of her data using her home computer. So I'm going to assume this was a personal computer issue. Thanks to everyone who provided input! Quote Link to comment https://forums.phpfreaks.com/topic/225984-losing-_get-and-_post-data/#findComment-1167842 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.