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

04-18-2004, 12:32 AM
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

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

04-18-2004, 02: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.

04-18-2004, 06: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?

04-18-2004, 06: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