what is wrong with this?
<?php
$score = 0;
if ($q1 == a) $score == $score + 1;
echo ("Your quiz score is ".$score."");
?>
it wont count...
First of all, this goes in the PHP forum.
A lot of mistakes in this one...
$q1 is not defined.
'a' is not a defined constant.
You're using '==' where you should be using '='
<?php
$score = 0;
$q1 = 5;
define('a', 5);
if ($q1 == a)
$score = $score + 1; // or just $score++;
echo ("Your quiz score is ".$score."");
?>
Try to apply something similar to your script (I assume your script is bigger than this). Can't really help you more without seeing more of the script.ok - imagine you have a simple questionnaire...
in the question.html form
<tr valign="top">
<td height="40" width="3%">1.</td>
<td width="37%">one</td>
<td align="center" width="16%">a) <input type="radio" name="q1" value="a"></td>
<td align="center" width="16%">b) <input type="radio" name="q1" value="b"></td>
<td align="center" width="17%">c) <input type="radio" name="q1" value="c"></td>
<td width="7%"> </td>
</tr>
sent to answers.php
<php?
$score = 0;
if ($q1 == a) $score = $score++;
echo ("Your quiz score is ".$score."");
?>
which wont validate or count...
and this next bit which does work (so please no one tell me it doesn't cause it does...)
<tr valign="top">
<td height="40" width="3%">1.</td>
<td width="37%">one</td>
<td align="center" width="16%">a) <input type="radio"<?phpif ($q1 == a){echo (' checked');} ?>></td>
<td align="center" width="16%">b) <input type="radio"<?phpif ($q1 == b){echo (' checked');} ?>></td>
<td align="center" width="17%">c) <input type="radio"<?phpif ($q1 == c){echo (' checked');} ?>></td>
<td align="center" width="7%">
<?phpif ($q1 == a){echo ('correct');} else {echo ('<b>a</b>');} ?>
</td>
</tr>
you can see, the out put does recognise that the varible value comes from the form - but where does it go wrong in the counting?i moved this to the php list and i explained the problem a little betterOriginally posted by nuclearvapid
what is wrong with this?
<?php
$score = 0;
if ($q1 == a) $score == $score + 1;
echo ("Your quiz score is ".$score."");
?>
it wont count...
how about this
<?php
$score = 0;
if ($_POST['q1'] == 'a') $score++;
echo "Your quiz score is ". $score;
?>Originally posted by nuclearvapid
and this next bit which does work (so please no one tell me it doesn't cause it does...)
how can it when it is the same as above which doesn't work.
$q1 == a
that will NEVER be true because a is a string and you didn't quote it.
$q1 == 'a'
so yeah I will tell you it doesn't work. clear your cache and you will see it doesn't work. does the radio button get checked? after you submit?funny enough yes!
go try it yourself
<!-- m --><a class="postlink" href="http://www.mfl-ucan.co.uk/l1/l1_h_smod_r3q.htmlfound">http://www.mfl-ucan.co.uk/l1/l1_h_smod_r3q.htmlfound</a><!-- m --> problem! while 'my' code does work - it only works with older versions of php. What you/scout posted is correct and while it doesn't work on legacy versions, it DOES works much better in up to date versions.
Thank you.
Onto next stage of dev!Glad you worked it out.
I tried the quiz, and having seen your code, and my french not being what it once was, I put 'a' on all questions, hoping to have at least one correct answer.. Dang! Tricky.Originally posted by nuclearvapid
found problem! while 'my' code does work - it only works with older versions of php. What you/scout posted is correct and while it doesn't work on legacy versions, it DOES works much better in up to date versions.
Thank you.
Onto next stage of dev!
yup, you should never use old versions of php. they are out dated and insecure. but the old version of php should still treat strings the same. but I will take your word for it as I don't run anything less then 4.1.2
<?php
$score = 0;
if ($q1 == a) $score == $score + 1;
echo ("Your quiz score is ".$score."");
?>
it wont count...
First of all, this goes in the PHP forum.
A lot of mistakes in this one...
$q1 is not defined.
'a' is not a defined constant.
You're using '==' where you should be using '='
<?php
$score = 0;
$q1 = 5;
define('a', 5);
if ($q1 == a)
$score = $score + 1; // or just $score++;
echo ("Your quiz score is ".$score."");
?>
Try to apply something similar to your script (I assume your script is bigger than this). Can't really help you more without seeing more of the script.ok - imagine you have a simple questionnaire...
in the question.html form
<tr valign="top">
<td height="40" width="3%">1.</td>
<td width="37%">one</td>
<td align="center" width="16%">a) <input type="radio" name="q1" value="a"></td>
<td align="center" width="16%">b) <input type="radio" name="q1" value="b"></td>
<td align="center" width="17%">c) <input type="radio" name="q1" value="c"></td>
<td width="7%"> </td>
</tr>
sent to answers.php
<php?
$score = 0;
if ($q1 == a) $score = $score++;
echo ("Your quiz score is ".$score."");
?>
which wont validate or count...
and this next bit which does work (so please no one tell me it doesn't cause it does...)
<tr valign="top">
<td height="40" width="3%">1.</td>
<td width="37%">one</td>
<td align="center" width="16%">a) <input type="radio"<?phpif ($q1 == a){echo (' checked');} ?>></td>
<td align="center" width="16%">b) <input type="radio"<?phpif ($q1 == b){echo (' checked');} ?>></td>
<td align="center" width="17%">c) <input type="radio"<?phpif ($q1 == c){echo (' checked');} ?>></td>
<td align="center" width="7%">
<?phpif ($q1 == a){echo ('correct');} else {echo ('<b>a</b>');} ?>
</td>
</tr>
you can see, the out put does recognise that the varible value comes from the form - but where does it go wrong in the counting?i moved this to the php list and i explained the problem a little betterOriginally posted by nuclearvapid
what is wrong with this?
<?php
$score = 0;
if ($q1 == a) $score == $score + 1;
echo ("Your quiz score is ".$score."");
?>
it wont count...
how about this
<?php
$score = 0;
if ($_POST['q1'] == 'a') $score++;
echo "Your quiz score is ". $score;
?>Originally posted by nuclearvapid
and this next bit which does work (so please no one tell me it doesn't cause it does...)
how can it when it is the same as above which doesn't work.
$q1 == a
that will NEVER be true because a is a string and you didn't quote it.
$q1 == 'a'
so yeah I will tell you it doesn't work. clear your cache and you will see it doesn't work. does the radio button get checked? after you submit?funny enough yes!
go try it yourself
<!-- m --><a class="postlink" href="http://www.mfl-ucan.co.uk/l1/l1_h_smod_r3q.htmlfound">http://www.mfl-ucan.co.uk/l1/l1_h_smod_r3q.htmlfound</a><!-- m --> problem! while 'my' code does work - it only works with older versions of php. What you/scout posted is correct and while it doesn't work on legacy versions, it DOES works much better in up to date versions.
Thank you.
Onto next stage of dev!Glad you worked it out.
I tried the quiz, and having seen your code, and my french not being what it once was, I put 'a' on all questions, hoping to have at least one correct answer.. Dang! Tricky.Originally posted by nuclearvapid
found problem! while 'my' code does work - it only works with older versions of php. What you/scout posted is correct and while it doesn't work on legacy versions, it DOES works much better in up to date versions.
Thank you.
Onto next stage of dev!
yup, you should never use old versions of php. they are out dated and insecure. but the old version of php should still treat strings the same. but I will take your word for it as I don't run anything less then 4.1.2