mcdof001 Posted September 29, 2007 Share Posted September 29, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/71151-solved-parse-error-syntax-error-unexpected-t_string/ Share on other sites More sharing options...
rarebit Posted September 29, 2007 Share Posted September 29, 2007 Look here: if ($exercise == 0 Hours) { $fit1 == 0 should be: if ($exercise == 0 Hours) { $fit1 = 0; Quote Link to comment https://forums.phpfreaks.com/topic/71151-solved-parse-error-syntax-error-unexpected-t_string/#findComment-357841 Share on other sites More sharing options...
hemlata Posted September 29, 2007 Share Posted September 29, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/71151-solved-parse-error-syntax-error-unexpected-t_string/#findComment-357844 Share on other sites More sharing options...
rarebit Posted September 29, 2007 Share Posted September 29, 2007 Told you i'd only just woken up, too obvious... I use strcmp on stuff like this as well... if(strcmp($x, "xyz") == 0) Quote Link to comment https://forums.phpfreaks.com/topic/71151-solved-parse-error-syntax-error-unexpected-t_string/#findComment-357848 Share on other sites More sharing options...
mcdof001 Posted September 29, 2007 Author Share Posted September 29, 2007 ill just try that 2nd one now the first 1 didnt work. Quote Link to comment https://forums.phpfreaks.com/topic/71151-solved-parse-error-syntax-error-unexpected-t_string/#findComment-357849 Share on other sites More sharing options...
mcdof001 Posted September 29, 2007 Author Share Posted September 29, 2007 thanks so much, working again! ill probably be on here again asking another question. sorry to not see the obvious! Quote Link to comment https://forums.phpfreaks.com/topic/71151-solved-parse-error-syntax-error-unexpected-t_string/#findComment-357854 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.