Jump to content

[SOLVED] Parse error: syntax error, unexpected T_STRING


mcdof001

Recommended Posts

Hi,

I have a page called results.php, that gets variables from a form and puts them into a mysql database.

I get an error when the form is submitted:-

Parse error: syntax error, unexpected T_STRING in /hosted/subs/ulmb.com/g/r/greenshawaida/public_html/results.php on line 12

Lines 12-24 are just a simple if statement.

if ($exercise == 0 Hours) {
    $fit1 == 0
} elseif ($exercise == 1 Hours) {
    $fit1 == 1;
} elseif ($exercise == 2 Hours) {
    $fit1 == 2;
} elseif ($exercise == 3 Hours) {
    $fit1 == 3;
} elseif ($exercise == 4 Hours) {
    $fit1 == 4;
} else {
    $fit1 == 5;
}

why isn't it working. i'm not very good at writing php, so if there is an obvious error i'm sorry!

Hello,

 

There are 2 mistakes in your code block

- First of missing ';' (Also pointed by rarebit)

 

- And another one of not using quotes while comparing string in if-elseif conditions. Modify your code with the following code block

if ($exercise == '0 Hours') {
    $fit1 == 0;
} elseif ($exercise == '1 Hours') {
    $fit1 == 1;
} elseif ($exercise == '2 Hours') {
    $fit1 == 2;
} elseif ($exercise == '3 Hours') {
    $fit1 == 3;
} elseif ($exercise == '4 Hours') {
    $fit1 == 4;
} else {
    $fit1 == 5;
}

 

Hope this will solve your issue.

Regards

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.