Page 1 of 1
parse error
Posted: Wed Mar 24, 2004 8:51 pm
by bawla
i get this error
Code: Select all
Parse error: parse error in /home/krunk/public_html/ghetto.php on line 12
and this is the script im using
Code: Select all
<?php
$points=NULL
if (isset($_POST['ques1'] = 'ques1_true')){
$points+5;
}
if (isset($_POST['ques2'] = 'ques2_true')){
$points+8;
}
if (isset($_POST['ques3'] = 'ques3_true')){
$points+7;
}
if (isset($_POST['ques4'] = 'ques4_true')){
$points+6;
}
if (isset($_POST['ques5'] = 'ques5_true')){
$points+5;
}
if (isset($_POST['ques5_2'] = 'ques5_2_true')){
$points+5;
}
if (isset($_POST['ques6'] = 'ques6_true')){
$points+3;
}
if (isset($_POST['ques7'] = 'ques7_true')){
$points+3;
}
if (isset($_POST['ques8'] = 'ques8_true')){
$points+15;
}
if (isset($_POST['ques9'] = 'ques9_true')){
$points+2;
}
if (isset($_POST['ques10'] = 'ques10_true')){
$points+7;
}
echo = $points;
?>
line 12 is
Code: Select all
if (isset($_POST['ques1'] = 'ques1_true')){
Posted: Wed Mar 24, 2004 8:52 pm
by John Cartwright
Code: Select all
<?php
$points=NULL
if (isset($_POST['ques1'] == 'ques1_true')){
$points+5;
}
elseif (isset($_POST['ques2'] == 'ques2_true')){
$points+8;
}
elseif (isset($_POST['ques3'] == 'ques3_true')){
$points+7;
}
elseif (isset($_POST['ques4'] == 'ques4_true')){
$points+6;
}
elseif (isset($_POST['ques5'] == 'ques5_true')){
$points+5;
}
elseif (isset($_POST['ques5_2'] == 'ques5_2_true')){
$points+5;
}
elseif (isset($_POST['ques6'] == 'ques6_true')){
$points+3;
}
elseif (isset($_POST['ques7'] == 'ques7_true')){
$points+3;
}
elseif (isset($_POST['ques8'] == 'ques8_true')){
$points+15;
}
elseif (isset($_POST['ques9'] == 'ques9_true')){
$points+2;
}
elseif (isset($_POST['ques10'] == 'ques10_true')){
$points+7;
}
echo $points;
?>
Not sure if your setting question to question_true.. if you are then use the = if not just use == ( checks to see if they are equal )
Posted: Wed Mar 24, 2004 8:53 pm
by tim
$points=NULL
whatever that is, $points=NULL;
Posted: Wed Mar 24, 2004 9:01 pm
by bawla
even after i change that i still get the same error
Posted: Wed Mar 24, 2004 9:06 pm
by markl999
You need to change all those..
if (isset($_POST['ques1'] == 'ques1_true')){
$points+5;
}
to
if (!empty($_POST['ques1']) && $_POST['ques1'] == 'ques1_true'){
$points += 5;
}
I'm sure you're just learning how to do stuff so i'll leave it there, but there is an infintely easier way to do what you're doing

Posted: Wed Mar 24, 2004 9:06 pm
by Goowe
Did you add that semi-colan after "NULL" like Tim said?
What is the error now?
[Sorry I'm running late]
Posted: Wed Mar 24, 2004 9:30 pm
by bawla
I'm sure you're just learning how to do stuff so i'll leave it there, but there is an infintely easier way to do what you're doing

tell me!! lol
Posted: Wed Mar 24, 2004 9:36 pm
by bawla
this is after i added the semicolon
Code: Select all
Parse error: parse error, expecting `','' or `')'' in /home/krunk/public_html/ghetto.php on line 12
Posted: Wed Mar 24, 2004 9:44 pm
by markl999
tell me!! lol
Well, here's an example
Code: Select all
<?php
$pointsarr = array(
'ques1' => 5,
'ques2' => 8,
'ques3' => 7,
'ques4' => 6,
'ques5' => 5,
'ques5_2' => 5,
'ques6' => 3,
'ques7' => 3,
'ques8' => 15,
'ques9' => 2,
'ques10' => 7
);
if(!empty($_POST)){
$points = 0;
foreach($_POST as $key=>$val){
if(isset($pointsarr[$key])){
$points += $pointsarr[$key];
}
}
echo $points;
}
?>
<html>
<body>
<form method="post" action="">
one <input type="checkbox" name="ques1" value="1"><br />
two <input type="checkbox" name="ques2" value="1"><br />
three <input type="checkbox" name="ques3" value="1"><br />
four <input type="checkbox" name="ques4" value="1"><br />
five <input type="checkbox" name="ques5" value="1"><br />
five_2 <input type="checkbox" name="ques5_2" value="1"><br />
six <input type="checkbox" name="ques6" value="1"><br />
seven <input type="checkbox" name="ques7" value="1"><br />
eight <input type="checkbox" name="ques8" value="1"><br />
nine <input type="checkbox" name="ques9" value="1"><br />
ten <input type="checkbox" name="ques10" value="1"><br />
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
Posted: Wed Mar 24, 2004 9:52 pm
by bawla
complicated enough
<<<- that is wut im doing right now, lol
how did u get $key, and $val, if i know wut they are , i'd understand it much better
Posted: Wed Mar 24, 2004 11:26 pm
by markl999
Here's the PHP bit again, with comments this time
Code: Select all
<?php
//an array that holds form field names and
//their matching points value
$pointsarr = array(
'ques1' => 5,
'ques2' => 8,
'ques3' => 7,
'ques4' => 6,
'ques5' => 5,
'ques5_2' => 5,
'ques6' => 3,
'ques7' => 3,
'ques8' => 15,
'ques9' => 2,
'ques10' => 7
);
//check if the form was submitted
if(!empty($_POST)){
$points = 0; //initialise the points to 0
//the line below will loop over all the posted form elements
//$key will be the form name (eg ques1)
//$val will be it's value (eg 1)
foreach($_POST as $key=>$val){
//the next line sees if the key is set in the points array
if(isset($pointsarr[$key])){
//if it is, then we take add the points value from the
//pointsarr array and add it onto the total points.
$points += $pointsarr[$key];
}
}
echo $points;
}
?>
Posted: Thu Mar 25, 2004 7:36 am
by tim
go to php.net and type in foreach() in the function search.