Jump to content

[SOLVED] Parse error: syntax error, unexpected T_STRING


scrap0346

Recommended Posts

I'm trying to setup a simple authentication for users but I keep getting this error:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/mikemeye/public_html/test/index.php on line 32

I'll admit I copied and pasted this code from a PHP forum, but I do understand HTML and the fuctions that are in the code, I'm just still working on the syntax of the functions.  Any help would be appreciated.  Thanks!


here's the code:

<?php
session_start();
require_once('connect.php');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Index</title>
<style type="text/css">
.container {
  text-align: center;
  border: 1px solid #000000;
  width: 300px;
}
td {
  text-align: left;
}
</style>
</head>
<body>
<table class="container" align="center" cellspacing="0" cellpadding="0">
  <tr>
      <td colspan="2" style="text-align:center;"><h1>Index</h1></td>
  </tr>
  <tr>
      <td colspan="2" style="text-align:center;">
        <?php
        if(isset($_SESSION['username'])) {
            $data = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `username`="'.$_SESSION['username'].'"'));
            echo 'You are logged in, '.$_SESSION['username'].'. <br /><br />Your last log in was '.date('l, F j, Y', $data['last_seen']).' <br /><br />You registered '.date('l, F j, Y', $data['date_registered']).'<br /><br /><a href="logout.php">Click here to logout</a>';
        }else{
            echo 'You aren't logged in.<br /><br />Please <a href="register.php">register</a> or <a href="login.php">log in.</a>';
        }
        ?>
      </td>
  </tr>
</table>
</body>
</html>


(connect.php just connects to the mysql database, it was just easier to put it in a separate .php file than have to rewrite it each time)
change
[code]
<?php
        if(isset($_SESSION['username'])) {
            $data = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `username`="'.$_SESSION['username'].'"'));
            echo 'You are logged in, '.$_SESSION['username'].'.
[/code]

to

[code]
<?php
        if(isset($_SESSION['username'])) {
            $data = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `username`="'.$_SESSION['username'].'"'); );
            echo 'You are logged in, '.$_SESSION['username'].'.
[/code]
In this echo statement:
[code]<?php
            echo 'You aren't logged in.

Please <a href="register.php">register[/url] or <a href="login.php">log in.[/url]';
?>[/code]
you have a single quote inside a string that is delimited by a single quote which effectively ends the string so PHP doesn't know what to make of the rest of the string. I would write it like this:
[code]<?php
            echo "You aren't" . ' logged in.

Please <a href="register.php">register[/url] or <a href="login.php">log in.[/url]';
?>[/code]
Other people would probably code it differently.

Ken
[quote author=kenrbnsn link=topic=120240.msg493019#msg493019 date=1167367581]
In this echo statement:
[code]<?php
            echo 'You aren't logged in.

Please <a href="register.php">register[/url] or <a href="login.php">log in.[/url]';
?>[/code]
you have a single quote inside a string that is delimited by a single quote which effectively ends the string so PHP doesn't know what to make of the rest of the string. I would write it like this:
[code]<?php
            echo "You aren't" . ' logged in.

Please <a href="register.php">register[/url] or <a href="login.php">log in.[/url]';
?>[/code]
Other people would probably code it differently.

Ken

[/quote]



hey thanks man. i can't believe i spent all that time on a stupid single quotation mark. now i'm feeling kinda stupid. thanks again!

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.