Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax error 1

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
Can someone tell me why this works:

<?php
session_start();
print 'The value of DB6 is: ' . $_SESSION['DB6'] . '
?>

But this doesn't:
<?php
session_start();
print 'The value of DB6 is: ' . $_SESSION['DB6'] . '
print 'The value of DB12 is: ' . $_SESSION['DB12'] . '
?>

Many thanks

 
Because you have a syntax error. The first code works because it ends there and the parser has nothing else to do. The second code wants to add something where the first one did not finish and the result is an error.

Every line in PHP has to be finished off by a semi-colon. At the end of the script, semi-colons are optional, but I would strongly advise you to come into habit of using them. Your code shows little understanding of how things work. You have a string that is delimited by single quotes. That string ends after is: where it is closed by the single quote. From then on, you concate the session variable. However, after that you concate something else which never ends. Since you never end your line (semi-colon), php just goes into the next line and tries to work things out but gets utterly confused in the next line. You need to put a lot more thought into your coding. It is not hard, you just have to use your head. This should work:
Code:
<?php
session_start();
print 'The value of DB6 is: ' . $_SESSION['DB6'];
print 'The value of DB12 is: ' . $_SESSION['DB12'];
?>
Please examine closely what I changed and try to understand it.
 
Many thanks Vragabond, very well explained. A worthy star
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top