Jump to content

Cannot Find The Syntax Error


jimfog

Recommended Posts

I cannot find the syntax error in the following code:

echo  "<div><a href="$_SERVER['PHP_SELF']".?month= ". $prev_month . "&year= ". $prev_year;

Is there a problem with the quotes?

Link to comment
Share on other sites

Ok, it worked, but why you inserted double quotes twice at the beginning and the end?

Link to comment
Share on other sites

It would be better to use single quotes to surround text as in the html etc, then you would not need to escape the double quotes within that html echo '<div><a href="'.$_SERVER['PHP_SELF'].'?month='.$prev_month.' &year= '.$prev_year.'"';

echo  '<div><a href="'.$_SERVER['PHP_SELF'].'?month='.$prev_month.'&year='.$prev_year.'"';

Link to comment
Share on other sites

these quotes issue is very complicated. Here is another line who(again) i cannot make it right.

echo    '<div class="monthname"'>$monthNames[$cMonth - 1].'kkk'. $cYear'</div>';

The class name is in double quotes-where is the error here? Is it ok for the string 'kkk' the way it is?

Link to comment
Share on other sites

The code you provided would work like this

echo '<div class="monthname">' . $monthNames[$cMonth - 1] . 'kkk' . $cyear . '</div>';

Let me explain. When you display an HTML link using echo, you actually display a string that's why you have to enclose it in a single or double-quotes. But you also want to display some PHP variables. The dot (.) is connecting all the parts of the echo statement so you have to use it in both ends. For example

echo 'string' . $variable . 'string';

. As you see, in your code you forgot to add the dot before $monthNames[$cMonth - 1] and what is more your single quote should go after > so that it is inside the string. I really hope i didn't make this more complicated for you. I am in a hurry, i'll probably be able to explain it more simple when i go home.

Link to comment
Share on other sites

Now i got it-at last. Thanks

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...