psychohagis Posted January 6, 2007 Share Posted January 6, 2007 I have the following bit of code to print out messages from a database:[code]<?php$dbcnx = @mysql_connect(MYSQLSERVER, 'DATABASE', 'PASSWORD');if (!dbcnx) { echo '<p>Unable to connect to the ' . 'database server at this time.</p>'; exit();}if (!mysql_select_db('bucksChild')) { exit('<p>Unable to locate the childminding ' . 'database at this time.</p>');}$messages = @mysql_query( 'SELECT id, from, subject, message, received, read, username FROM messages, users WHERE to=' . $userid . 'AND from=users.id');if (!$messages) { exit('<p>Error performing query: ' . mysql_error() . '</p>);}While ($row = mysql_fetch_array($messages)) { $id=$row['id']; //THIS IS LINE 137 $from=$row['from']; $subject=$row['subject']; $received=$row['received']; $read=$row['read']; $username=$row['username']; $sent=kiedy(received);echo "<tr>\n";echo "<td class=message><a href=http://www.buckschildminding.org.uk/members/messages/message.php?id='$id'>$subject</a></td>\n";echo "<td class=messageinfo><a href=http://www.buckschildming.org.uk/members/profile.php?uid='$from'>$username</a></td>\n";echo "<td class=messageinfo>$sent</td>\n";echo "</tr>\n";}?>[/code]but when I run it i get:[quote]Parse error: parse error, unexpected T_STRING in /home/fhlinux178/b/buckschildminding.org.uk/user/htdocs/members/messages/index.php on line 137[/quote] Link to comment https://forums.phpfreaks.com/topic/33105-unexpected-t_string/ Share on other sites More sharing options...
rab Posted January 6, 2007 Share Posted January 6, 2007 wrap it in curly brackets like so {$row['from']} Link to comment https://forums.phpfreaks.com/topic/33105-unexpected-t_string/#findComment-154242 Share on other sites More sharing options...
papaface Posted January 6, 2007 Share Posted January 6, 2007 your code should be:[code]<?php$dbcnx = @mysql_connect(MYSQLSERVER, 'DATABASE', 'PASSWORD');if (!dbcnx) { echo '<p>Unable to connect to the ' . 'database server at this time.</p>'; exit();}if (!mysql_select_db('bucksChild')) { exit('<p>Unable to locate the childminding ' . 'database at this time.</p>');}$messages = @mysql_query( 'SELECT id, from, subject, message, received, read, username FROM messages, users WHERE to=' . $userid . 'AND from=users.id');if (!$messages) { exit('<p>Error performing query: ' . mysql_error() . '</p>');}While ($row = mysql_fetch_array($messages)) { $id=$row['id']; //THIS IS LINE 137 $from=$row['from']; $subject=$row['subject']; $received=$row['received']; $read=$row['read']; $username=$row['username']; $sent=kiedy(received);echo "<tr>\n";echo "<td class=message><a href=http://www.buckschildminding.org.uk/members/messages/message.php?id='$id'>$subject</a></td>\n";echo "<td class=messageinfo><a href=http://www.buckschildming.org.uk/members/profile.php?uid='$from'>$username</a></td>\n";echo "<td class=messageinfo>$sent</td>\n";echo "</tr>\n";}?>[/code]You missed a ending ' Link to comment https://forums.phpfreaks.com/topic/33105-unexpected-t_string/#findComment-154244 Share on other sites More sharing options...
psychohagis Posted January 6, 2007 Author Share Posted January 6, 2007 ok i need more help i know get the problem: [quote]Error performing query: 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 'to=1 AND from=users.id' at line 2[/quote] Link to comment https://forums.phpfreaks.com/topic/33105-unexpected-t_string/#findComment-154247 Share on other sites More sharing options...
papaface Posted January 6, 2007 Share Posted January 6, 2007 You will need to post the whole file here for that. Link to comment https://forums.phpfreaks.com/topic/33105-unexpected-t_string/#findComment-154248 Share on other sites More sharing options...
psychohagis Posted January 6, 2007 Author Share Posted January 6, 2007 <?phpsession_start();if (!isset($_SESSION['userid']) or $_SESSION['userid'] ==''){exit('<meta http-equiv=refresh content=0;URL=http://www.MYSITE.org.uk/members/signin.php?error=12>');}$userid=$_SESSION['userid'];function kiedy($ts) { $ts=time()-$ts; if ($ts<60) // <1 minute return $ts." seconds ago"; elseif ($ts<60*60) // <1 hour return floor($ts/60)." minutes ago"; elseif ($ts<60*60*2) // <2 hour return "1 hour ago"; elseif ($ts<60*60*24) // <24 hours = 1 day return floor($ts/60*60)." hours ago"; elseif ($ts<60*60*24*2) // <2 days return "1 day ago"; elseif ($ts<60*60*24*7) // <7 days = 1 week return floor($ts/60*60*24)." days ago"; elseif ($ts<60*60*24*30.5) // <30.5 days ~ 1 month return floor($ts/60*60*24*7)." weeks ago"; elseif ($ts<60*60*24*365) // <365 days = 1 year return floor($ts/60*60*24*30.5)." months ago"; else // more than 1 year return floor($ts/60*60*24*365)." years ago";};?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Bucks Childminding Association</title><link rel="stylesheet" href="/style/style.css" type="text/css"><link rel="stylesheet" href="/style/message.css" type="text/css"></head><body><div id="topsection"><TABLE STYLE="filter:shadow(color=#880000, strength=3)"><TR><TD><center>Buckinghamshire childminding <br>association</TABLE></div><div id="topbar"> <div id="navcontainer"> <div id="topnav"> <ul> <li id="current"><a href="#"><span>Home</span></a></li> <li><a href="messageboard.html"><span>Message Board</span></a></li> <li><a href="information.html"><span>Information</span></a></li> </ul> </div> <div id="userinfo"> <?phpif (!isset($_SESSION['userid']) or $_SESSION['userid'] ==''){echo '<a href=/members/signup.php>sign up</a> | <a href=/members/signin.php>sign in</a>';} else {$username=$_SESSION['username'];echo 'signed in as <a href=/members/>' . $username . '</a> | <a href=/members/signout.php>sign out</a>';} ?> </div> </div></div><div id="maincontainer"><div id="contentwrapper"><div id="contentcolumn"><div id="messagecontainer"><div id="title"> Messages</div><table class=threads> <tr> <th class="message">Subject</th> <th class="messageinfo">From</th> <th class="messageinfo">Received</th> </tr><?php$dbcnx = @mysql_connect('MYSQLSERVER', 'DATABASE', 'PASSWORD');if (!dbcnx) { echo '<p>Unable to connect to the ' . 'database server at this time.</p>'; exit();}if (!mysql_select_db('bucksChild')) { exit('<p>Unable to locate the childminding ' . 'database at this time.</p>');}$messages = @mysql_query( 'SELECT id, from1, subject, message, received, read1, username FROM messages, users WHERE to=' . $userid . ' AND from=users.id');if (!$messages) { exit('<p>Error performing query: ' . mysql_error() . '</p>');}While ($row = mysql_fetch_array($messages)) { $id=$row['id']; //THIS IS LINE 137 $from=$row['from']; $subject=$row['subject']; $received=$row['received']; $read=$row['read']; $username=$row['username']; $sent=kiedy(received);echo "<tr>\n";echo "<td class=message><a href=http://www.buckschildminding.org.uk/members/messages/message.php?id='$id'>$subject</a></td>\n";echo "<td class=messageinfo><a href=http://www.buckschildming.org.uk/members/profile.php?uid='$from'>$username</a></td>\n";echo "<td class=messageinfo>$sent</td>\n";echo "</tr>\n";}?></table></div> <div id=contentfooter><a href="#top" class="toplink">Back to top</a><a href="#" class="sitedesignedby"><br /><br /><img src="/style/footerpic.bmp"></a></div></div></div><div id="leftcolumn"><div class="title"> Home </div> <ul> <li><a href="#"><span>News</span></a></li> <li><a href="#"><span>Events</span></a></li> <li><a href="#"><span>Pics</span></a></li> </ul></div></div><div id="footer"><p></p></div></body></html> Link to comment https://forums.phpfreaks.com/topic/33105-unexpected-t_string/#findComment-154251 Share on other sites More sharing options...
papaface Posted January 6, 2007 Share Posted January 6, 2007 try:[code]$messages = @mysql_query( 'SELECT id, from1, subject, message, received, read1, username FROM messages, users WHERE to="' . $userid . '" AND from="users.id"');if (!$messages) { exit('<p>Error performing query: ' . mysql_error() . '</p>');}[/code] Link to comment https://forums.phpfreaks.com/topic/33105-unexpected-t_string/#findComment-154254 Share on other sites More sharing options...
psychohagis Posted January 6, 2007 Author Share Posted January 6, 2007 no it gives me the exact same problem Link to comment https://forums.phpfreaks.com/topic/33105-unexpected-t_string/#findComment-154256 Share on other sites More sharing options...
psychohagis Posted January 6, 2007 Author Share Posted January 6, 2007 *bump* Link to comment https://forums.phpfreaks.com/topic/33105-unexpected-t_string/#findComment-154263 Share on other sites More sharing options...
PFMaBiSmAd Posted January 6, 2007 Share Posted January 6, 2007 [b]from[/b] is a reserved keyword. In your query this is apparently a column name. If this is so, you must enclose it in back-ticks:AND `from`=users.id Link to comment https://forums.phpfreaks.com/topic/33105-unexpected-t_string/#findComment-154270 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.