parse error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

parse error

Post 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')){
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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 )
Last edited by John Cartwright on Wed Mar 24, 2004 8:55 pm, edited 2 times in total.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

$points=NULL
whatever that is, $points=NULL;
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post by bawla »

even after i change that i still get the same error
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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 :o
Goowe
Forum Commoner
Posts: 94
Joined: Mon Mar 15, 2004 9:51 am
Location: Southeast Alaska

Post by Goowe »

Did you add that semi-colan after "NULL" like Tim said?

What is the error now?

[Sorry I'm running late]
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post 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 :o
tell me!! lol
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post 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
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

tell me!! lol
Well, here's an example :o

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>
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post 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
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Here's the PHP bit again, with comments this time :o

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;
}
?>
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

go to php.net and type in foreach() in the function search.
Post Reply