Jump to content
Sign in to follow this  
Spudinski

Parse/Synax Errors

Recommended Posts

This article, or more reference is to help people new to PHP scripting in general but is more focussed on errors you may find on a MCCodes based engine.

We will mainly cover common types of phrase errors, or more widely known as syntax errors. Here are a few errors and examples on how to fix them.

 

Parse error: parse error, unexpected T_STRING

This will be the most common of syntax errors. There is no "absolute" reason why this may happen, but I'll mention a few it might occur.

1. You might have forgotten to end a line with a semi-colon, usually just check these first.

2. An unclosed quote( ' or " ) or bracket( } or ] ), meaning that the function, variable or statement was not ended correctly.

3. Unclosed comments are one of my favorites for this error, make sure you open and close your comments correctly.

It is possible for this error to point to the same line that the error actually is, but mostly it is further up in the script(usually one line).

 

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING

This error goes hand to hand with the previous one, but usually only 1. applies. A missing quote is usually the mistake.

 

Parse error: syntax error, unexpected $end

The main culpret for this errors are curley brackets( expecially } ). Make sure each statement, whether it be a function, if-else statement, switches or loops, is closed with a curley bracket.

 

Parse error: syntax error, unexpected T_STRING, expecting ‘,’ or ‘;’

This may be casued by not escaping quotes correctly, or simply forgetting to end the statement with a semi-colon.

This could also be because of a missing join character ( , or . ). Check for this when you are joining variables and strings together.

Refer to the first solution for more information.

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

Usually a using the ` character in my experiance. But it could also appear when you do not escape quotes, or missed closing a quote. Mainly just incorrect usage of quotes now that I think of it.

 

The best advice I can give anyone who experiances a lot of syntax/phrase errors is to do yourself the plesure of buying a decent PHP IDE(Integrated Development Environment). A good paid one is Zend Studio by Zend, but if you are on the short bit of life NetBeans by Sun which will do the job just as good.

If anyone experiances any other phrase/syntax errors, please post them here and I will add the solution to them in this thread.

Share this post


Link to post
Share on other sites

echo '<tr>

<td>'.stripslashes($r['hNAME']).'</td>

<td><a href="http://viewuser.php?u='.$r['userid'].'" target="_blank">'.stripslashes($r['username']).'</a></td>

<td>'.number_format($r['uhouseMood']).' mood bar</td>

<td><a href="http://houses.php?page=move&id='.$r['uhouseId'].'" target="_blank">Move in</a>

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/morgan95/public_html/houses.php on line 64

sorry but i still cant work it out :(

Edited by morgan1122

Share this post


Link to post
Share on other sites

Assuming this is line 64

<td><a href="http://houses.php?page=move&id='.$r['uhouseId'].'" target="_blank">Move in</a>

 

Maybe it can be fixed if you correct this -> '

Spotted one more... so fix those and you most likely have that running fine

Note: Someone place these on the proper thread!

Edited by Lithium

Share this post


Link to post
Share on other sites
Assuming this is line 64
<td><a href="http://houses.php?page=move&id='.$r['uhouseId'].'" target="_blank">Move in</a>

 

Maybe it can be fixed if you correct this -> '

Spotted one more... so fix those and you most likely have that running fine

Note: Someone place these on the proper thread!

Sorry i dont know what to change it too im rubbish at coding and trying to learn it

Share this post


Link to post
Share on other sites
<?php
include_once('globals.php');
echo '<p class="heading">Your Houses</p>';
switch ($_GET['page'])
{
  case 'move': move_house(); break;
  case 'move_out': move_out(); break;
  case 'estate': estate_agent(); break;
  case 'sell': sell_house(); break;
  case 'rentals': rental_market(); break;
  case 'rent': rent_house(); break;
  case 'upgrade': upgrade_house(); break;
  default: houses_index(); break;
}
function houses_index()
{
  global $ir;
  $houses = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `houses` ON (`hID` = `uhouseHouse`) LEFT JOIN `users` ON (`userid` = `uhouseOwner`) WHERE (`uhouseOwner` = '%u' || `uhouseTenant` = '%u') AND `uhouseId` != '%d'", $ir['userid'], $ir['userid'], $ir['house']));
  echo '<table width="600">
  <tr>
  <td width="50%" align="center"><a href="http://houses.php?page=estate" target="_blank">Estate agent</a></td>
  <td width="50%" align="center"><a href="http://houses.php?page=rentals" target="_blank">Rent a house</a></td>
  </tr>
  </table>

';
  if($ir['house'])
   {
     $fetch = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `houses` ON (`hID` = `uhouseHouse`) WHERE (`uhouseId` = '%u')", $ir['house']));
     $h = mysql_fetch_assoc($fetch);
     echo '<b>Current house:</b>


     <table width="300" class="table">
     <tr>
     <th width="50%">Current house</th>
     <th width="50%">Move out</th>
     </tr>
     <tr>
     <td>'.stripslashes($h['hNAME']).'</td>
     <td><a href="http://houses.php?page=move_out" target="_blank">Move out</a></td>
     </tr>
     </table>

';
   }
  echo '<table width="600" class="table">
  <tr>
  <th width="25%">House name</th>
  <th width="25%">Owner</th>
  <th width="25%">Mood value</th>
  <th width="25%">Manage</th>
  </tr>';
  if(!mysql_num_rows($houses))
   {
     echo '<tr>
     <td colspan="5">You have no houses at this time, purchase one at the estate agent\'s.</td>
     </tr>';
   }
  while($r = mysql_fetch_assoc($houses))
   {



   echo '<tr>';
   echo '<td>' . stripslashes($r['hNAME']) . '</td>';
   echo '<td><a  href="http://viewuser.php?u=' . $r['userid'] . '"  target="_blank">' . stripslashes($r['username']) . '</a></td>';
   echo '<td>' . number_format($r['uhouseMood']) . ' mood bar</td>';
   echo '<td><a href="http://houses.php?page=move&id=' . $r['uhouseId'] . '" target="_blank">Move in</a>';
   echo '</tr>';

     echo '<a href="http://houses.php?page=sell&id='.$r['uhouseId'].'" target="_blank">Sell house</a>';
     echo '<a href="http://houses.php?page=rent&id='.$r['uhouseId'].'" target="_blank">Rent house</a>';
     echo '<a href="http://houses.php?page=upgrade&id='.$r['uhouseId'].'" target="_blank">Add upgrades</a></td>';
     echo '</tr>';
   }
  echo '</table>';
}
function move_house()
{
  global $ir;
  $fetch = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `houses` ON (`hID` = `uhouseHouse`) LEFT JOIN `users` ON (`userid` = `uhouseOwner`) WHERE (`uhouseId` = '%u')", abs((int) $_GET['id'])));
  if(!isset($_GET['id']))
   {
     echo 'You did not select a house to move in to.';
   }
  else if(!mysql_num_rows($fetch))
   {
     echo 'You cannot move into a non-existant house.';
   }
  else
   {
     $r = mysql_fetch_assoc($fetch);
     if($r['uhouseOwner'] != $ir['userid'] AND $r['uhouseTenant'] != $ir['userid'])
      {
        echo 'You are not permitted to move into this house.';
      }
     else if($r['uhouseRTime'] AND $r['uhouseOwner'] == $ir['userid'])
      {
        echo 'You cannot move into a house while it is being rented to another member.';
      }
     else
      {
        mysql_query(sprintf("UPDATE `users` SET `house` = '%d', `maxwill` = '%d' WHERE (`userid` = '%u')", abs((int) $_GET['id']), $r['uhouseMood'], $ir['userid']));
        echo 'You have moved into the '.stripslashes($r['hNAME']).', You now have a maximum mood bar of '.number_format($r['uhouseMood']).'.';
      }
   }
}
function move_out()
{
  global $ir;
  $fetch = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `houses` ON (`hID` = `uhouseHouse`) LEFT JOIN `users` ON (`userid` = `uhouseOwner`) WHERE (`uhouseId` = '%u')", $ir['house']));
  if(!mysql_num_rows($fetch))
   {
     echo 'You cannot move out of a non-existant house.';
   }
  else
   {
     $r = mysql_fetch_assoc($fetch);
     if($r['uhouseOwner'] != $ir['userid'] AND $r['uhouseTenant'] != $ir['userid'])
      {
        echo 'You are not permitted to move out of this house.';
      }
     else
      {
        mysql_query(sprintf("UPDATE `users` SET `house` = '0', `maxwill` = '100' WHERE (`userid` = '%u')", $ir['userid']));
        echo 'You have moved out of the '.stripslashes($r['hNAME']).', You now have a maximum mood bar of 100.';
      }
   }
}
function sell_house()
{
  global $ir;
  $fetch = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `houses` ON (`hID` = `uhouseHouse`) LEFT JOIN `users` ON (`userid` = `uhouseOwner`) WHERE (`uhouseOwner` = '%u') AND (`uhouseId` = '%u')", $ir['userid'], abs((int) $_GET['id'])));
  if(!isset($_GET['id']))
   {
     echo 'You did not select a house to sell.';
   }
  else if(!mysql_num_rows($fetch))
   {
     echo 'You cannot attempt to sell a non-existant house.';
   }
  else
   {
     $r = mysql_fetch_assoc($fetch);
     if($r['uhouseOwner'] != $ir['userid'])
      {
        echo 'You do not own this house, so don\'t attempt to sell it.';
      }
     else if($r['uhouseTenant'])
      {
        echo 'You cannot sell a house while it is being rented to another member.';
      }
     else
      {
        mysql_query(sprintf("UPDATE `users` SET `money` = `money` + '%d' WHERE (`userid` = '%u')", $r['houseCost'], $ir['userid']));
        mysql_query(sprintf("DELETE FROM `owned_houses` WHERE (`uhouseId` = '%u')", abs((int) $_GET['id'])));
        echo 'You have sold the '.stripslashes($r['hNAME']).' for a total of $'.number_format($r['hPRICE']).'.';
      }
   }
}
function estate_agent()
{
  global $ir;
  if(isset($_GET['id']))
   {
     $house = mysql_query(sprintf("SELECT * FROM `houses` WHERE (`hID` = '%u')", abs((int) $_GET['id'])));
     $r = mysql_fetch_assoc($house);
     if(!mysql_num_rows($house))
      {
        echo 'You cannot attempt to purchase a non-existant house.';
      }
     else if($ir['money'] < $r['hPRICE'])
      {
        echo 'You cannot afford to purchase this house right now, come back another time.';
      }
     else
      {
        mysql_query(sprintf("UPDATE `users` SET `money` = `money` - '%d' WHERE (`userid` = '%u')", $r['hPRICE'], $ir['userid']));
        mysql_query(sprintf("INSERT INTO `owned_houses` (`uhouseId`, `uhouseOwner`, `uhouseHouse`, `uhouseMood`) VALUES ('NULL','%u', '%d', '%d')", $ir['userid'], $r['hID'], $r['hWILL']));
        echo 'You have purchased the '.stripslashes($r['hNAME']).' for a total of $'.number_format($r['houseCost']).'!';
      }
   }
  else
   {
     $houses = mysql_query(sprintf("SELECT * FROM `houses` ORDER BY `hWILL` ASC"));
     echo '<table width="600" class="table">
     <tr>
     <th>House name</th>
     <th>Mood value</th>
     <th>Cost</th>
     </tr>';
     while($r = mysql_fetch_assoc($houses))
      {
        echo '<tr>
        <td><a href="http://houses.php?page=estate&id='.$r['hID'].'" target="_blank">'.stripslashes($r['hNAME']).'</a></td>
        <td>'.number_format($r['hWILL']).' mood bar</td>
        <td>$'.number_format($r['hPRICE']).'</td>
        </tr>';
      }
     print '</table>';
   }
}
function rental_market()
{
  global $ir;
  if(isset($_GET['id']))
   {
     $house = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `houses` ON (`hID` = `uhouseHouse`) LEFT JOIN `users` ON (`userid` = `uhouseOwner`) WHERE (`uhouseId` = '%u')", abs((int) $_GET['id'])));
     $r = mysql_fetch_assoc($house);
     if(!mysql_num_rows($house))
      {
        echo 'You cannot rent a house that does not exist.';
      }
     else if($r['uhouseOwner'] == $ir['userid'])
      {
        echo 'You own this house at this time, You cannot rent it aswell.';
      }
     else
      {
        mysql_query(sprintf("UPDATE `owned_houses` SET `uhouseTenant` = '%d' WHERE (`uhouseId` = '%u')", $ir['userid'], abs((int) $_GET['id'])));
        echo 'You are now renting the '.stripslashes($r['hNAME']).' for a total of $'.number_format($r['uhouseRent']).' each night!';
      }
   }
  else
   {
     $houses = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `houses` ON (`hID` = `uhouseHouse`) LEFT JOIN `users` ON (`userid` = `uhouseOwner`) WHERE `uhouseTenant` = '0' AND `uhouseRent` > '0' ORDER BY `uhouseRent` ASC"));
     echo '<table width="600" class="table">
     <tr>
     <th>House name</th>
     <th>Owner</th>
     <th>Mood value</th>
     <th>Cost each night</th>
     <th>Rental time</th>
     <th>Manage</th>
     </tr>';
     while($r = mysql_fetch_assoc($houses))
      {
        echo '<tr>
        <td>'.stripslashes($r['hNAME']).'</td>
        <td><a href="http://userprofile.php?id='.$r['userid'].'" target="_blank">'.stripslashes($r['username']).'</a></td>
        <td>'.number_format($r['uhouseMood']).' mood bar</td>
        <td>$'.number_format($r['uhouseRent']).'</td>
        <td>'.number_format($r['uhouseRTime']).' nights</td>
        <td><a href="http://houses.php?page=rentals&id='.$r['uhouseId'].'" target="_blank">Rent house</a></td>
        </tr>';
      }
     print '</table>';
   }
}
function rent_house()
{
  global $ir;
  $fetch = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `houses` ON (`hID` = `uhouseHouse`) LEFT JOIN `users` ON (`userid` = `uhouseOwner`) WHERE (`uhouseOwner` = '%u') AND (`uhouseId` = '%u')", $ir['userid'], abs((int) $_GET['id'])));
  if(!isset($_GET['id']))
   {
     echo 'You did not select a house to rent out to members.';
   }
  else if(!mysql_num_rows($fetch))
   {
     echo 'You cannot attempt to rent out a non-existant house.';
   }
  else
   {
     $r = mysql_fetch_assoc($fetch);
     if($r['uhouseOwner'] != $ir['userid'])
      {
        echo 'You do not own this house, so don\'t attempt to rent it out to people.';
      }
     else if($r['uhouseTenant'])
      {
        echo 'You cannot rent out a house while it is being rented to another member.';
      }
     else
      {
        if(isset($_POST['time']) AND isset($_POST['cost']))
         {
           mysql_query(sprintf("UPDATE `owned_houses` SET `uhouseRent` = '%d', `uhouseRTime` = '%d' WHERE (`uhouseId` = '%u')", abs((int) $_POST['cost']), abs((int) $_POST['time']), abs((int) $_GET['id'])));
           echo 'You have added the '.stripslashes($r['hNAME']).' the the rental market at a cost of $'.number_format($_POST['cost']).' per night.';
         }
        else
         {
           echo '<form action="houses.php?page=rent&id='.$_GET['id'].'" method="post">
           <table width="600">
           <tr>
           <td><b>Amount of nights:</b></td>
           <td><input type="text" name="time" value="30" /></td>
           </tr>
           <tr>
           <td><b>Cost per nights:</b></td>
           <td><input type="text" name="cost" value="250" /></td>
           </tr>
           <tr>
           <td colspan="2" align="center"><input type="submit" value="Submit rental" /></td>
           </tr>
           </table>
           </form>';
         }
      }
   }
}
function upgrade_house()
{
  global $ir;
  if(!isset($_POST['id']))
   {
     if(isset($_GET['id']))
      {
        echo '<form action="houses.php?page=upgrade&id='.$_GET['id'].'" method="post" name="upgrades">
        <table class="table" width="600">
        <tr>
        <th width="45%">Upgrade name</th>
        <th width="25%">Mood gain</th>
        <th width="25%">Cost</th>
        <th width="5%"></th>
        </tr>';
        $fetch = mysql_query("SELECT * FROM `house_upgrades` ORDER BY `upgradeMood` ASC");
        while ($r = mysql_fetch_assoc($fetch))
         {
           echo '<tr>
           <td>'.stripslashes($r['upgradeName']).'</td>
           <td>'.number_format($r['upgradeMood']).' mood</td>
           <td>$'.number_format($r['upgradeCost']).'</td>
           <td><input type="radio" name="id" value="'.$r['upgradeId'].'" onClick="document.upgrades.submit();" /></td>
           </tr>';
         }
        echo '</table>';
      }
     else
      {
        echo 'You did not select a house to add upgrades to.';
      }
   }
  else
   {
     $upgrade = mysql_query(sprintf("SELECT * FROM `house_upgrades` WHERE `upgradeId` = '%u'", abs((int) $_POST['id'])));
     if(!mysql_num_rows($upgrade))
      {
        echo 'This upgrade does not exist at this time, if this problem continues report it to staff.';
      }
     else if(!isset($_GET['id']))
      {
        echo 'You did not select a house to add upgrades to.';
      }
     else
      {
        $house = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `houses` ON (`hID` = `uhouseHouse`) LEFT JOIN `users` ON (`userid` = `uhouseOwner`) WHERE (`uhouseId` = '%u')", abs((int) $_GET['id'])));
        $h = mysql_fetch_assoc($house);
        $r = mysql_fetch_array($upgrade);
        if(!mysql_num_rows($house))
         {
           echo 'You cannot add upgrades to a non-existant house.';
         }
        else if($h['uhouseOwner'] != $ir['userid'])
         {
           echo 'You are not permitted to add upgrades to this house.';
         }
        else if($ir['money'] < $r['upgradeCost'])
         {
           echo 'You do not have enough cash to purchase this upgrade right now.';
         }
        else
         {
           $check = mysql_query(sprintf("SELECT * FROM `owned_upgrades` WHERE (`ownupHouse` = '%u') AND (`ownupUpgrade` = '%d')", abs((int) $_GET['id']), abs((int) $_POST['id'])));
           if(mysql_num_rows($check))
            {
              echo 'This house has this upgrade at this time, it cannot be bought again.';
            }
           else
            {
              mysql_query(sprintf("UPDATE `users` SET `money` = `money` - '%d' WHERE `userid` = '%u'", $r['upgradeCost'], $ir['userid']));
              mysql_query(sprintf("UPDATE `owned_houses` SET `uhouseMood` = `uhouseMood` + '%d' WHERE `uhouseId` = '%u'", $r['upgradeMood'], abs((int) $_GET['id'])));
              mysql_query(sprintf("INSERT INTO `owned_upgrades` (`ownupId`, `ownupHouse`, `ownupUpgrade`) VALUES ('NULL','%u', '%d')", abs((int) $_GET['id']), abs((int) $_POST['id'])));
              echo 'You have purchased the '.stripslashes($r['upgradeName']).' for $'.number_format($r['upgradeCost']).'.';
            }
         }
      }
   }
}
$h->endpage();
?>

 

Got error Parse error: syntax error, unexpected '<' in /home/morgan95/public_html/houses.php on line 74

The below is showing up in gray so there is somthing wrong with this but what??

http://houses.php?page=rent&id='.$r['uhouseId'].'" target="_blank">Rent house</a>';
Edited by morgan1122

Share this post


Link to post
Share on other sites

Change lines 72-74 to this:

echo '<a href="houses.php?page=sell&id='.$r['uhouseId'].'" target="_blank">Sell house</a>';

echo '<a href="houses.php?page=rent&id='.$r['uhouseId'].'" target="_blank">Rent house</a>';

echo '<a href="houses.php?page=upgrade&id='.$r['uhouseId'].'" target="_blank">Add upgrades</a></td>';

Share this post


Link to post
Share on other sites

" target="_blank" or http:// is not needed in your script morgan, as for I am guessing you took that script off the forum, and it was an older post?

When these forums were upgraded to the new layout ALL older posts and threads relating from 2008-2010 were effected through the bbcode, which left those in the codes, they are not part of the script that had been originally posted on here.

Share this post


Link to post
Share on other sites
     echo '<tr>
        <td><a href="houses.php?page=estate&id='.$r['hID'].'"  target="_blank">'.stripslashes($r['hNAME']).'</a></td>
        <td>'.number_format($r['hWILL']).' mood bar</td>
        <td>$'.number_format($r['hPRICE']).'</td>
        </tr>';
      }

line 195 is the first line im getting

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/morgan95/public_html/houses.php on line 196

Share this post


Link to post
Share on other sites

This thread is here to help you fix errors by giving some basic idea of what the issue could be. Please create a new thread for any problems you have rather then asking in this thread. Just keeps this as an "How to fix" thread only. Thanks.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...