aww. i'm so sorry for posting again. i have so many questions. i'm so sorry. ahm. i was just wondering if my code is possible if ever i'm going to insert a remarks to my database.

here is my code:

$totalg=($totala+$totalb+$totalc+$totald+$totale+$totalf)/6;

if(totalg <= 5.00 && totalg >= 4.51){
	$remark=Excellent;}
else(totalg <= 4.50 && totalg >= 3.51){
	$remark=Very Satisfactory;}
else(totag <= 3.50 && totalg >= 2.51){
	$remark=Satisfactory;}
else(totalg <= 2.50 && totalg >= 1.51){
	$remark=Fair;}
else(totalg <= 1.50 && totalg >= 1.00){
	$remark=Needs Improvement;}

i think it's possible but i have this parse error. i don't know where. please and thank you so much. :)

You need to put quote around strings - words that are NOT PHP keywords - ex: $remark="Excellent"; because Excellent is NOT a php keyword. The same goes for the other remarks.

also, totalg IS a variable, so you MUST prefix it with a dollar sign in every instance of totalg.
WRONG: if(totalg <= 5.00 && totalg >= 4.51){ CORRECT: if($totalg <= 5.00 && $totalg >= 4.51){

You need to change 'else' to 'elseif' for each of the statements.

as hielo suggested, Quotation marks are required around the remark values

Also 'totalg' needs the '$' prefix! It is a variable.

Sort out your indentation and curly braces - It makes things much easier to read and debug...

<?php
	$totalg=($totala+$totalb+$totalc+$totald+$totale+$totalf)/6;

	if($totalg <= 5.00 && $totalg >= 4.51)
	{
		$remark="Excellent";
	}
	elseif($totalg <= 4.50 && $totalg >= 3.51)
	{
		$remark="Very Satisfactory";
	}
	elseif($totag <= 3.50 && $totalg >= 2.51)
	{
		$remark="Satisfactory";
	}
	elseif($totalg <= 2.50 && $totalg >= 1.51)
	{
		$remark="Fair";}
	elseif($totalg <= 1.50 && $totalg >= 1.00)
	{
		$remark="Needs Improvement";
	}

	echo $remark;
?>

You need to put quote around strings - words that are NOT PHP keywords - ex: $remark="Excellent"; because Excellent is NOT a php keyword. The same goes for the other remarks.

also, totalg IS a variable, so you MUST prefix it with a dollar sign in every instance of totalg.
WRONG: if(totalg <= 5.00 && totalg >= 4.51){ CORRECT: if($totalg <= 5.00 && $totalg >= 4.51){

oh. okay. my bad. so i changed all the codes so here is my new code:

$totalg=($totala+$totalb+$totalc+$totald+$totale+$totalf)/6;

if($totalg <= 5.00 && $totalg >= 4.51){
	$remark="Excellent";}
elseif($totalg <= 4.50 && $totalg >= 3.51){
	$remark="Very Satisfactory";}
elseif($totalg <= 3.50 && $totalg >= 2.51){
	$remark="Satisfactory";}
elseif($totalg <= 2.50 && $totalg >= 1.51){
	$remark="Fair";}
else($totalg <= 1.50 && $totalg >= 1.00){
	$remark="Needs Improvement";}

But i have parse error on the else part.

You need to put quote around strings - words that are NOT PHP keywords - ex: $remark="Excellent"; because Excellent is NOT a php keyword. The same goes for the other remarks.

also, totalg IS a variable, so you MUST prefix it with a dollar sign in every instance of totalg.
WRONG: if(totalg <= 5.00 && totalg >= 4.51){ CORRECT: if($totalg <= 5.00 && $totalg >= 4.51){

oh yes. yes po. i already did but i have parse error on the else part.

there is no such thing as:
else OPEN_PARENTHESIS condition CLOSE_PARENTHESIS { ... }

the proper syntax for an else is a "braced block" with NO condition:
else{
...
}

there is:
if OPEN_PARENTHESIS condition CLOSE_PARENTHESIS { ... }

and also
elseif OPEN_PARENTHESIS condition CLOSE_PARENTHESIS { ... }

so if you really want to include that condition, you should use and elseif

there is no such thing as:
else OPEN_PARENTHESIS condition CLOSE_PARENTHESIS { ... }

the proper syntax for an else is a "braced block" with NO condition:
else{
...
}

there is:
if OPEN_PARENTHESIS condition CLOSE_PARENTHESIS { ... }

and also
elseif OPEN_PARENTHESIS condition CLOSE_PARENTHESIS { ... }

so if you really want to include that condition, you should use and elseif

oh. okay. that worked but i have this error:

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 2

what does that mean? i'm so sorry.. and thank you so much. :)


OH. okay. i knew it already. :) thank you so much for the help guys! ! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.