Forum Moderators: coopster

Message Too Old, No Replies

variables not appearing

         

dkin

9:53 pm on Dec 17, 2004 (gmt 0)

10+ Year Member



I have this script. Except $prev_answer and $prev_votes
do not show up after the first submitting of the form, after 2 or 3 they do but why do they not show up after the first click?

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

$new_score = $score + $myrow['vote_total'];

$new_votes = $myrow['vote_amount'] + 1;

$answer = ($new_score) / ($new_votes);

$query="UPDATE pics SET vote_amount='$new_votes', vote_total='$new_score' where pic_id = '$myrow[pic_id]' ";
mysql_query($query);
}

print '<center><table>'
. '<tr><td align="center" valign="middle">';
print '<form action='.$PHP_SELF.' method="post">'
. '1 <input type="radio" name="score" value="1" onClick="this.form.submit()"/>'
. '2 <input type="radio" name="score" value="2" onClick="this.form.submit()"/>'
. '3 <input type="radio" name="score" value="3" onClick="this.form.submit()"/>'
. '4 <input type="radio" name="score" value="4" onClick="this.form.submit()"/>'
. '5 <input type="radio" name="score" value="5" onClick="this.form.submit()"/>'
. '6 <input type="radio" name="score" value="6" onClick="this.form.submit()"/>'
. '7 <input type="radio" name="score" value="7" onClick="this.form.submit()"/>'
. '8 <input type="radio" name="score" value="8" onClick="this.form.submit()"/>'
. '9 <input type="radio" name="score" value="9" onClick="this.form.submit()"/>'
. '10 <input type="radio" name="score" value="10" onClick="this.form.submit()"/>'
. '</td></tr><tr>'
. '<td>';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$prev_answer = $_POST['answer'];
$prev_votes = $_POST['new_v'];
$prev_alt = $_POST['alt'];
$prev_image = $_POST['image'];
print 'Average '.round($prev_answer, 2).' with '.$prev_votes.' votes' ;
print ' You Voted '.$score.'<br><img src="upload/thumb/th_'.$prev_image.'".jpg alt="'.$prev_alt.'">';
}
print '</td>'
. '<td align="center" valign="top"><br><br>'
. '<img alt="'.$myrow[pic_name].'" src="upload/thumb/'.$myrow[pic_id].'.jpg" />'
. '<br><br>'.$myrow[descrip].'<br>'
. '<input type="hidden" name="new_v" value="'.$new_votes.'" /><input type="hidden" name="answer" value="'.$answer.'" /><input type="hidden" name="alt" value="'.$myrow[pic_name].'" /><input type="hidden" name="image" value="'.$myrow[pic_id].'" /></form>'
. '</td>'
. '<td></td>'
. '</tr>'
. '</table></center>';

?>

jatar_k

11:58 pm on Dec 17, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



on a quick look, it seems they aren't set the first time it is submitted, only the second time do they become set.

when viewing the first load of the form, look at the source and see if they are set there. You should then be able to get a better idea of why.

dkin

10:08 am on Dec 18, 2004 (gmt 0)

10+ Year Member



no they are not being set and I ont know why. As far as I know they should be. In tghe source file, wherever there is supposed to be one of those variables, its just space.

Any ideas on how I can fix this?

jatar_k

8:50 pm on Dec 18, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



considering that they are initialized this way

$prev_answer = $_POST['answer'];
$prev_votes = $_POST['new_v'];

they should only get set once there is $_POST data available. You should check for the existence of the post data and then, if it isn't there, set them to some default value.