I've searched for a little while and even saw some Q&A's about it, but none satisfied me... Please take a look at this skeleton code and tell me what's wrong.
I'm trying to post a feedback form back to the same page, (The form and MySQL INSERT code are on the same include).
Here's the code: (I put some debug stuff in to see what was going on, I'll print out the output at the end)
[anypage.php]
<?
//UserID set up here...
yadda yadda: Whatever is on the page...
//DEBUG CODE
$fromAbove = "CAN";
//Feedback Form Include
include("http://www.bookbuoy.com/comment-submit.php?returnURL=$PHP_SELF");
//I'll explain the returnURL in the Included text
?>
[comment-submit.php]
<?
//DEBUG FOR SEVERAL LINES
//Is this global call wrong?
global $fromAbove;
if(!isset($fromAbove)) {
$fromAbove = "can't";
} //If the variable isn't passed to the include, set $fromAbove to "can't"
print "problem originated in $pointOfProblem<BR>";
print "I $fromAbove see variables inside includes...";
//FORM-PROCESS CODE
//Check if a feedback form was just submitted by seeing if a hidden variable from the form was set... And then insert into DB
if(isset($pointOfProblem) {
//Connect to database, this code is tried and true
include_once("http://www.bookbuoy.com/dbconnect.php");
$nextQuery = "INSERT INTO Comments (userID, CommentText, etc.) VALUES ('$uID', '$inquiryText', etc.)";
//DEBUG, this query seems to come out alright...
print $nextQuery;
mysql_query($nextQuery);
//Give the user confirmation of feedback
print "<BR><BR><I>Thank you for your feedback.</I>";
}
?>
<BR><BR>
<?//Some INPUT's screened?>
<FORM METHOD=post ACTION="http://www.bookbuoy.com<? echo $returnURL;?>">
<TABLE ALIGN=center BORDER=0>
<TR><TD><TEXTAREA WRAP=VIRTUAL NAME="inquiryText" COLS=28 ROWS=5></TEXTAREA><TD><INPUT TYPE=submit VALUE=Submit></TR>
</TABLE>
<?
/This is why I needed to pass that variable in, because when I just say PHP_SELF it gives me the comment-submit link instead of the original link... Better way to do this? Only a secondary problem... Because at least it works right now.../?>
<INPUT TYPE=hidden Name=pointOfProblem VALUE="<?echo $returnURL;?>">
<INPUT TYPE=hidden Name=refID VALUE=<?echo $uID;?>>
</FORM>
[DISPLAYED CODE AFTER SUBMIT]
yadda yadda page stuff...
problem originated in
I can't see variables inside includes...
/Meaning the variable wasn't passed to the included part, even after a global declaration.../
//And then, of course, the form is here...
/No entries have made it into the database... (except when I just open comment-submit.php on it's own, but then there's no include problem/