...

View Full Version : Variable passed with GET not working as expected



Lau
04-17-2004, 11:32 PM
Hey everyone,

I'm having a bit of a head scrashing problem here.
I have a php file calling itself on submit:
This is only part of the file (I assume this is where the problem is, although not sure):


$url = "write_review.php?class=".$titleTable."&id=".$id;
echo "url is ".$url;
echo "<form action='".$url."' method='get'>";
// ============= display ===================
echo "<table width=60% border=0 cellpadding=5>";
echo "<tr height=20><td colspan=2 align=center><font size=+1>Ratings</font></td></tr>";
for ($i=0; $i<$j ;$i++) {
if ($hname[$i] != 'reviewer' && $hname[$i] != 'comment') {
echo "<tr><td align=right><i>" .$hdisplay[$i]. "</i></td>";
echo "<td align=left><input type='radio' name='".$hname[$i]."' value=1>1
<input type='radio' name='".$hname[$i]."' value=2>2
<input type='radio' name='".$hname[$i]."' value=3>3
<input type='radio' name='".$hname[$i]."' value=4>4
<input type='radio' name='".$hname[$i]."' value=5>5</td></tr>";
}
elseif ($hname[$i] == 'comment') {
echo "<tr height=20><td colspan=2 align=center><font size=+1>".$hdisplay[$i]."</font></td></tr>";
echo "<tr><td colspan=2 align=center>
<textarea name='".$hname[$i]."' rows=5 cols=70></textarea></td></tr>";
}// end elseif
} // end for
echo "<tr><td colspan=2 align=center><input type='submit' value='Submit'></td></tr>";
echo "</table></form>";

The echo "url is ".$url displays the right value, so it should go to that url. Instead, It goes to "write_review.php?comment="... Where does the comment come from????? :confused: :confused:
I really don't get where that comes from at all.
You can check it out at http://www1.coe.neu.edu/~lleccia/ISYG250/proj5/index.php try to write a review (id: user, pw: pass) and see when submitting

sidney
04-18-2004, 12:56 AM
you are useing get to pass data from form so comment is added when you submit the form

firepages
04-18-2004, 01:56 PM
Your sample page bears no relation to the problem in the code you post , e.g. it does not use a form , I can only assume that in your real caod you managed to rewrite $url value before you actually used it.

The only time PHP will alter your script is when rewriting urls with a session id , & unless you have set your session name to 'comment' what you describe can't happen, probbably a typo somewhere.

Lau
04-18-2004, 05:01 PM
sidney - well.. It works. I changed get to post, and the file reload itself!

I don't really understand why that is though...
I'm using GET to retrieve variables from the url, so I should be using get, shouldn't I?

sidney
04-18-2004, 05:06 PM
the form was adding the get vars to the url so over writing exsisting possibly

the way to do it by get would be to have hidden fields in form for vars class and id and then when form is submitted all vars in form would be added to url



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum