Unexpected T_STRING

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

adamb10
Forum Commoner
Posts: 91
Joined: Sat Jun 24, 2006 7:44 pm

Unexpected T_STRING

Post by adamb10 »

I dont know what line is causing the error since I checked the line and the code looks fine but php is still complaining.

Code: Select all

Parse error: syntax error, unexpected T_STRING, expecting ']' in /home/adamb10/public_html/ub2/index.php on line 293
Code below...

Code: Select all

<?
session_start();

//index.php

// START MEMORY BUFFER
ob_start();

//Load required files
require('sources/functions.php');

//COUNTER STSRT
$c_ip = $HTTP_COOKIE_VARS["user_ip"];
$counter_file = "sources/counter.txt";
$counter_file_line = file ($counter_file);
if(!$c_ip) {
setcookie("user_ip", $REMOTE_ADDR, time()+360000);  $counter_file_line[0]++;
$cf = fopen ($counter_file, "w+");fputs($cf, "$counter_file_line[0]"); fclose($cf);
}
elseif($c_ip != $REMOTE_ADDR){
$counter_file_line[0]++; $cf = fopen ($counter_file, "w+");
fputs($cf, "$counter_file_line[0]");
fclose($cf);
}

//END COUNTER

//Essential Functions
db_connect();

//Prepare for Query in 5..4..3..2..1
function query($query){
    $sql = "$query";
    $result = mysql_query($sql);
    return mysql_fetch_array ($result);
}


// Figure out the limit for the query based
// on the current page number.


//QUERY START
$row = query("SELECT * FROM settings"); //settings query
$row1 = query("SELECT * FROM colors"); //colors query
$row2 = query("SELECT * FROM images");

$max_results = $row['maxshow'];
$from = ($page * $max_results);

$q1 = 'SELECT * FROM Bans'; //ban query
      $r1 = mysql_query($q1) or die(mysql_error());

if($row['postorder'] == "descend") { //Comment Query 1
  $q = 'SELECT * FROM comments ORDER BY Date DESC LIMIT '.$from.', '.$max_results.'';
       $r = mysql_query($q) or die(mysql_error());
    
} else{
if($row['postorder'] == "ascend"){ //Comment Query 2
$q = 'SELECT * FROM comments ORDER BY Date ASC LIMIT '.$from.', '.$max_results.'';
       $r = mysql_query($q) or die(mysql_error());
    }
}

$hf = query("SELECT * FROM hf"); //HF Query
if (!$hf) {
   die('Invalid query: ' . mysql_error());
   }
//QUERY END

//CSS BEGIN
echo '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<head>
<title>'.$row['title'].'</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style type="text/css">
<!--


a:link {
    color: #'.$row1['link'].';
    text-decoration: none;
}
a:visited {
    color: #'.$row1['visitedlink'].';
    text-decoration: none;
}
a:active {
    color: #'.$row1['activelink'].';
    text-decoration: none;
}
a:hover {
    color: #'.$row1['hoverlink'].';
    text-decoration: none;
    }
body {
    background-color: #'.$row1['bodybg'].';
    font-family: '.$row1['fontfamily'].';
    font-size: '.$row1['fontsize'].';
    color: #'.$row1['font'].';
    margin:0px;
    ';
if ($row1['bodybgimage'] != "") {
echo 'background-image: url('.$row1['bodybgimage'].');';
}
echo '
    }
.titlebg {
    background-color: #'.$row1['titlebg'].';
    font-family: '.$row1['titlefontfamily'].';
    font-size: '.$row1['titlefontsize'].';
    color: #'.$row1['titlefont'].'; ';
    if ($row1['tilebgimage'] == "") {
    echo '
    background-image: url('.$row1['titlebgimage'].');';
}
        echo '
        }
.windowbg {
    background-color: #'.$row1['windowbg'].';
    font-family: '.$row1['windowfontfamily'].';
    font-size: '.$row1['windowfontsize'].';
    color: #'.$row1['windowfont'].';';
    if ($row1['windowbgimage'] != "") {
    echo 'background-image: url('.$row1['windowbgimage'].');';
    }
    echo '
    }
.windowbg2 {
    background-color: #'.$row1['window2bg'].';
    font-family: '.$row1['window2fontfamily'].';
    font-size: '.$row1['window2fontsize'].';
    color: #'.$row1['window2font'].';';
    if($row1['window2bgimage'] != "") {
    echo 'background-image: url('.$row1['window2bgimage'].');';
    }
  
    echo '
     }
.border {
    background-color: #'.$row1['border'].';
    }
td {
    font-size: 11px;
    }
input,textarea {
    font-family: '.$row1['fontfamily'].';
    font-size: 11px;
    }
select {
    font-family: '.$row1['fontfamily'].';
    font-size: 11px;
    }
    --!>
    </style>
    <title>'.$row1['title'].'</title>
</head>

<body>';
//CSS END

if($_GET['action'] == "")
{
getUserIp();
}



//echo out the Guestbook Header
guestbook_header();
echo '<br><br><br>';
require('sources/actions.php');

//Check if this really is index.php.
if($_GET['action'] == "")
{
echo '<br>'.$hf['header'].'';
if($row['posting'] == "enabled") {
if($row['kwikpost'] == "yes"){
if($row['kwikpostlocation'] == "top"){
kwikpost();
}
}}
}
//PAGINATON STARTS HERE
if(!isset($_GET['page'])){
    $page = 0;
} else {
    $page = $_GET['page'];
}



echo '<br><br>
<table style="width: 55%;" class="border" border="0" cellpadding="4" cellspacing="1" align="center">';


//COMMENT SYSTEM BEGIN
if($_GET['action'] == ""){
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM comments"),0);


// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
echo '<center>Select a Page: ';
// Build Page Number Hyperlinks

if($page > 0){
    $prev = ($page - 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}

for($i = 0; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i ";
        } else {
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
    }
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
}
{

while($row = mysql_fetch_array($r)){

///END PAGINATION, PROCEED TO NORMAL CODE

echo "</center>";

//TURN TABLE CONTENT TO VARIABLES FOR EASE OF USE
$date = explode("|",   $row['date']);
            $name =    $row['name'];
            $comment = $row['comment'];
            $email =   $row['email'];
            $website = $row['website'];
            $aim     = $row['aim'];
            $msn    =  $row['msn'];
            $yahoo =   $row['yahoo'];
            $hideemail = $row['hideemail'];
            
//QUERY SETTINGS AGAIN
$row = query("SELECT * FROM settings");
if(!isset($cmd)){
echo '
<tr class="windowbg2">
          <td style="width: 27%;">';
//HI, WHATS YOUR NAME?
           echo
          "$name
         <br>";
         if($hideemail != "o") {
         
         if($row['links'] != "images"){
         echo "
         <a href=\"mailto: $email\">
             [email]</a>";
             } else {
              echo '<a href="mailto: '.$email.'"><img src="'.$row2['email'].'" border="0"></a>';
              }}
             
         if($aim != ""){
         
         if($row['links'] != "images") {
         
         echo " <a href=\"aim:goim?screenname=$aim&message=Hello\">
             [aim]</a>";
          } else {
          echo '<a href="aim:goim?screenname='.$aim.'&message=Hello"><img src="'.$row2['aim'].'" border="0"></a>';
          }}
         
           if($msn != ""){
           if($row['links'] != "images") {
         echo ' <font title="$msn" alt="'.$msn.'">[msn]</font>';
         } else {
          echo '<font title="$msn" alt="$msn"><img src="'.$row2['msn'].'" border="0"></font>';
          }}

           if($yahoo != ""){
           if($row['links'] != "images") {
         echo '<a href="http://edit.yahoo.com/config/send_webmesg?.target='.$yahoo.'">
             [yahoo]</a>';
          } else {
          echo '<a href="http://edit.yahoo.com/config/send_webmesg?.target='.$yahoo.'"><img src="'.$row2['yahoo'].'" border="0">';
          }}

            if($website != "") {
            if($row['links != "images"){
            echo '<a href="'.$website.'">[website]</a>';
            } else { 
            echo '<a href="'.$website.'"><img src="'.$row2['website'].'" border="0"></a>';
            }}
            echo '</td> <td>';
      
//DATE SYSTEM
       $d = $row['date'];
                $month = date("M");
                $day = date("d");
                $year = date("Y");

//MORE DATESYSTEN
echo 'Posted on ';
if($date['0']==$month && $date['1']==$day && $date['3']==$year){
                        echo '<b>Today</b>';
                } elseif($date['0']==$month && $date['1']==$day-1 && $date['3']==$year){
                        echo '<b>Yesterday</b>';
                } else {
                        echo '<b>'.$date['0'].' '.$date['1'].''.$date['2'].', '.$date['3'].'</b>';
                }
                echo ' at <b>'.$date['4'].'</b>';
        }

echo   "<br><br>
      
$comment
           </td>
    </tr>";
   }

echo '
<table>
<br>';

//KWIK POST
$row = query("SELECT * FROM settings");
if($row['posting'] == "enabled") {
if($row['kwikpost'] == "yes"){
if($row['kwikpostlocation'] == "bottom"){
kwikpost();
}}}

echo '
'.$hf['footer'].'';

        }}

//COMMENT SYSTEM END
copyright();

// FLUSH MEMORY BUFFER (CLEANER THEN LEAVING IT OUT)
ob_flush();
?>
basdog22
Forum Contributor
Posts: 158
Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece

Post by basdog22 »

on line 293
just paste this line of code here or try to number the code.
adamb10
Forum Commoner
Posts: 91
Joined: Sat Jun 24, 2006 7:44 pm

Post by adamb10 »

Code: Select all

echo '<a href="'.$website.'">[website]</a>';
Line 293.
basdog22
Forum Contributor
Posts: 158
Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece

Post by basdog22 »

Try:

Code: Select all

echo "<a href=".$website.">[website]</a>";
            } else { 
            echo "<a href=".$website."><img src=".$row2['website']." border=\"0\"></a>"; 
            }}
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

That's not the problem. This is (it can be seen clearly from the highlighter).

Code: Select all

if($row['links != "images"){
            echo '<a href="'.$website.'">[website]</a>';
            } else {
Should be:

Code: Select all

if($row['links'] != "images"){
            echo '<a href="'.$website.'">[website]</a>';
            } else {
adamb10
Forum Commoner
Posts: 91
Joined: Sat Jun 24, 2006 7:44 pm

Post by adamb10 »

The error moved down to 295...

Code: Select all

echo "<a href=".$website."><img src=".$row2['website']." border=\"0\"></a>";
Robert Plank
Forum Contributor
Posts: 110
Joined: Sun Dec 26, 2004 9:04 pm
Contact:

Post by Robert Plank »

adamb10 wrote:The error moved down to 295...

Code: Select all

echo "<a href=".$website."><img src=".$row2['website']." border="0"></a>";
When you get an unexpected string error the problem is usually you forgot to close something on the line ABOVE that one. So post lines 290-295.
adamb10
Forum Commoner
Posts: 91
Joined: Sat Jun 24, 2006 7:44 pm

Post by adamb10 »

Code: Select all

if($website != "") {
            if($row['links != "images"){
           echo "<a href=".$website.">[website]</a>";
            } else {
            echo "<a href=\".$website.\"><img src=\".$row2['website'].\" border=\"0\"></a>";
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Same problem bro.

Code: Select all

<?php
if($website != "") { 
    if($row['links'] != "images") { 
        echo "<a href=\"$website\">[website]</a>"; 
    } else { 
        echo "<a href=\"$website\"><img src=\"{$row2['website']}\" border=\"0\"></a>";
    }
}
?>
Your concatenation was throwing things off also.
adamb10
Forum Commoner
Posts: 91
Joined: Sat Jun 24, 2006 7:44 pm

Post by adamb10 »

Thanks!

P.S. How are you supposed to indent the { and }? I never knew the right way.
Robert Plank
Forum Contributor
Posts: 110
Joined: Sun Dec 26, 2004 9:04 pm
Contact:

Post by Robert Plank »

adamb10 wrote:Thanks!

P.S. How are you supposed to indent the { and }? I never knew the right way.
Most PHPers including me:

Code: Select all

if (stuff) {
   crud
}
Most of the other CS majors I know do it this way cause that's how they were taught:

Code: Select all

if (stuff)
{
   crud
}
I can't stand that, the brackets line up but it adds too much space
adamb10
Forum Commoner
Posts: 91
Joined: Sat Jun 24, 2006 7:44 pm

Post by adamb10 »

So pretty much you line up the closing bracket with the beginning of the if/else?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

The PEAR standard is:

Code: Select all

<?php
control (condition) {
    // Execute, indented four spaces, not tabs, per indent
}
?>
phpBB standard is:

Code: Select all

<?php
control (condition)
{
    // Execute, indented 1 tab that is equal to four spaces
}
?>
Use what you are comfortable with, unless you are in a group project. Then use the group standard. Either works.
adamb10
Forum Commoner
Posts: 91
Joined: Sat Jun 24, 2006 7:44 pm

Post by adamb10 »

Thanks, I'll format my code right now as it's not the cleanest. :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

adamb10 wrote:Thanks, I'll format my code right now as it's not the cleanest. :)
I suggest using an editor that does syntax highlighting. You would have spotted the issue with the unclosed string really quickly as you were typing this way. If eveything goes red you've forgotten to close the string somewhere.

FYI: I use

Code: Select all

if ($foo)
{
    //do something
}
Why do I do it that way? Precisely for the reason ~Robert Plank avoids it... it creates more space. Space doesn't hurt in your code, it makes it more readable/less bunched up that's all.
Post Reply