Jump to content

unexpected T_STRING


psychohagis

Recommended Posts

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

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

<?php
session_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">
   
<?php
if (!isset($_SESSION['userid']) or $_SESSION['userid'] =='')
{
echo '<a href=/members/signup.php>sign up</a>&nbsp|&nbsp<a href=/members/signin.php>sign in</a>';
} else {

$username=$_SESSION['username'];

echo 'signed in as <a href=/members/>' . $username . '</a>&nbsp|&nbsp<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">&nbspMessages</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

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.