Jump to content

Losing $_GET and $_POST data


cyberRobot

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

 

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.