I've just uploaded my production site to Go Daddy so I can get it testing on the actual server, etc... I've run into a bug that I can't figure out for the life of me. Here's what's happening:
I'm allowing users to input a "project" consisting of four fields: project name, project category, project date, and project description. From the first page, it takes their information submitted through POST into a second page where it displays the information they submitted for confirmation. So far, nothing has been put into the database. Upon pressing "Submit" on the confirm page, it again sends their info through POST (this time as hidden fields) to the final page where the query runs that puts it into the database. Here's the code:
//draw form containing project details and submit form. This form calls an action on the next page to actually submit the project. The function passes the user submitted values as hidden fields so as to pass via post to the actual submit function.
if (!$result)
{
echo 'Sorry, there was a problem entering your project into the database. The error was '.mysql_error();
exit;
}
else
{
echo 'Done! Your project is now in the database!';
}
}
The problem is, when it gets to the third page, it doesn't have the info they submitted - it simply passes through as blank. That is, UNLESS I hit refresh. Then, it resends the info and everything works as it should. Obviously, I don't want the user having to refresh everytime they want to submit something. Anything jump out that might be the problem?
<div id = "current_proj">
<p>Your Current Projects</p><hr />
<?php myCurrentProj($user_id); ?>
</div>
<div id = "confirm">
<?php submitProj($user_id, $user_user_type); ?> <!-- just for your information, these variables are set via a function that loads global variables according to whichever user is logged in at the time. -->
</div>
I've tried printing the vars, and the same thing happens. Basically, the first time I submit, they come up empty. If I hit refresh, they fill in correctly.
I'm thinking it may have something to do with variable scope. I've fixed the problem for now by using $_SESSION['var'] instead of $_POST['var'] but I'd still like to know why the latter is being screwy.
Have you tried using $_REQUEST instead of $_POST, shouldnt make a difference. But wont hurt to try. Also try submitting the form using GET to see if the same issue occurs with the querystring.
When you were printing the $_POST data, did you print inside the function?
You could try assigning the variables outside the function, then give them global scope inside the function.
Bookmarks