scrap0346 Posted December 29, 2006 Share Posted December 29, 2006 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 32I'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:<?phpsession_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) Link to comment https://forums.phpfreaks.com/topic/32149-solved-parse-error-syntax-error-unexpected-t_string/ Share on other sites More sharing options...
insrtsnhere13 Posted December 29, 2006 Share Posted December 29, 2006 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] Link to comment https://forums.phpfreaks.com/topic/32149-solved-parse-error-syntax-error-unexpected-t_string/#findComment-149197 Share on other sites More sharing options...
kenrbnsn Posted December 29, 2006 Share Posted December 29, 2006 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 Link to comment https://forums.phpfreaks.com/topic/32149-solved-parse-error-syntax-error-unexpected-t_string/#findComment-149198 Share on other sites More sharing options...
scrap0346 Posted December 29, 2006 Author Share Posted December 29, 2006 [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! Link to comment https://forums.phpfreaks.com/topic/32149-solved-parse-error-syntax-error-unexpected-t_string/#findComment-149204 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.