Jump to content


Photo

Seeking Your Genius: Parse error: parse error, unexpected $ in ...


  • Please log in to reply
15 replies to this topic

#1 ridiculous

ridiculous
  • Members
  • PipPipPip
  • Advanced Member
  • 175 posts

Posted 02 October 2006 - 06:43 PM

I have to admire anyone who is proficient enough with PHP to render me advice here today, simply because my nascient debugging experiences have nearly driven me to psychotic acts of violence-boy am I frustrated.

I've looked over the script inserted below for hours and I can't seem to identify the cause of a parsing error I keep getting

Parse error: parse error, unexpected $ in /home/content/s/t/a/starsonline/html/study/u/table.php on line 62.

It's probably quite simple but I don't have the expertise to solve the problem.
-----------------------------------------------------------------------------------

<?
session_start();

{
  $result = mysql_pconnect('localhost', 'password', 'user');
  if (!$result)
      return false;
  if (!mysql_select_db('db'))
      return false;

  return $result;
}

// Begin your table outside of the array

{echo '<table width="100%" border="0" cellpadding="4" cellspacing="0">
    <tr>
        <td width="110"><b>Event Date</b></td>
        <td><b> Event Title</b></td>
    </tr>';

// Define your colors for the alternating rows

$color1 = '#CCFFCC';
$color2 = '#BFD8BC';
$row_count = 0;

// Perform an statndard SQL query:

$sql_events = mysql_query('SELECT posted, title, location,
FROM jobs ORDER BY posted') or die (mysql_error());

// We are going to use the '$row' method for this query. This is just my preference.

while ($row = mysql_fetch_array($sql_events)) {
    $event_date = $row['event_date'];
    $event_title = $row['event_title'];

    /* Now we do this small line which is basically going to tell
    PHP to alternate the colors between the two colors we defined above. */

    $row_color = ($row_count % 2) ? $color1 : $color2;

    // Echo your table row and table data that you want to be looped over and over here.

    echo '<tr>
    <td width="110" bgcolor="$row_color" nowrap>
    $article_date</td>
    <td bgcolor="$row_color">
    <a href="articles.php?cmd=full_article&article_id=$article_id">$article_title</a></td>
    </tr>';

    // Add 1 to the row count

    $row_count++;
}

// Close out your table.

echo '</table>';

?>


#2 ridiculous

ridiculous
  • Members
  • PipPipPip
  • Advanced Member
  • 175 posts

Posted 02 October 2006 - 06:45 PM

Also, do Dreamweaver or PHP Eclipse have native debugging utilities that automatically resolve or better describe the cause of these kinds of errors?

#3 ridiculous

ridiculous
  • Members
  • PipPipPip
  • Advanced Member
  • 175 posts

Posted 02 October 2006 - 06:47 PM

One other thing, Phil Collins is an animal. A complete animal.

#4 Hi I Am Timbo

Hi I Am Timbo
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 02 October 2006 - 06:57 PM

The problem is with mismatched brackets. 

I'm not sure what the random brackets are, like in line 3, but they aren't needed. 

Remove the { around the echo and you should be fine.  There is not closing bracket.


#5 ridiculous

ridiculous
  • Members
  • PipPipPip
  • Advanced Member
  • 175 posts

Posted 02 October 2006 - 07:00 PM

Thank you, thank you, thank you.



#6 ridiculous

ridiculous
  • Members
  • PipPipPip
  • Advanced Member
  • 175 posts

Posted 02 October 2006 - 07:01 PM

Does the unexpected $ error occur strictly when you've screwed up your brackets?

#7 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 02 October 2006 - 07:04 PM

no. the $ is arbitrary and changes depending on the error. it points to the first thing it sees that is unexpected, following something you have done.  so when you get an 'unexpected blah' error, look to the previous lines for your error
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#8 ridiculous

ridiculous
  • Members
  • PipPipPip
  • Advanced Member
  • 175 posts

Posted 02 October 2006 - 07:12 PM

Well, that's both interesting and daunting...because I tend to get these errors directed at the final line of the script. For example:


---------------

Parse error: parse error, unexpected $ in /home/content/s/t/a/starsonline/html/strippedgirl/u/output_fns.php on line 71

----------------


<?

function do_jobs_header($title)
{
  // print an HTML header
?>
  <html>
  <head>
    <title><?=$title?></title>
    <style>
      body { font-family: Arial, Helvetica, sans-serif; font-size: 13px }
      li, td { font-family: Arial, Helvetica, sans-serif; font-size: 13px }
      hr { color: #3333cc; width=300; text-align=left}
      a { color: #000000 }
    </style>
  </head>
  <body>
  <img src="jobs.gif" alt="Big Ops" border=0
      align=left valign=bottom height = 55 width = 57>
  <h1>&nbsp;Stripped Girl ONline</h1>
  <hr>
<?
  if($title)
    do_html_heading($title);
}


function display_job_listings()
{
?>

<html>
<head>
<title>Displaying MySQL Data</title>
</head>
<body>


//////connection script



<table>

<?

$sql = "SELECT * FROM jobs";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td>".$row['date']."</td>";
echo "<td>".$row['title']."</td>";
echo "<td>".$row['description']."</td>";
echo "<td>".$row['location']."</td>";
echo "<td>".$row['compensation']."</td>";
echo "<td>".$row['required']."</td>";
echo "<td>".$row['preferred']."</td>";
echo "<td>".$row['notes']."</td>";
echo "</tr>";

?>


</table>
</body>
</html>

}




#9 Hi I Am Timbo

Hi I Am Timbo
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 02 October 2006 - 07:13 PM

That's because the unexpected thing is the ?>

It is expecting you to close the brackets before it quits parsing php.

#10 ridiculous

ridiculous
  • Members
  • PipPipPip
  • Advanced Member
  • 175 posts

Posted 02 October 2006 - 07:14 PM

Wow. That epitomizes somebody that doesn't have a clue what the hell they're doing, doesn't it?

#11 ridiculous

ridiculous
  • Members
  • PipPipPip
  • Advanced Member
  • 175 posts

Posted 02 October 2006 - 07:15 PM

You're awesome. I really, really appreciate the help.

#12 ridiculous

ridiculous
  • Members
  • PipPipPip
  • Advanced Member
  • 175 posts

Posted 02 October 2006 - 07:23 PM

Alright, I took the hint on the last host and tried to fix my code. I came up with this:


<?

function do_jobs_header($title)
{
  // print an HTML header
?>
  <html>
  <head>
    <title><?=$title?></title>
    <style>
      body { font-family: Arial, Helvetica, sans-serif; font-size: 13px }
      li, td { font-family: Arial, Helvetica, sans-serif; font-size: 13px }
      hr { color: #3333cc; width=300; text-align=left}
      a { color: #000000 }
    </style>
  </head>
  <body>
  <img src="jobs.gif" alt="Big Ops" border=0
      align=left valign=bottom height = 55 width = 57>
  <h1>&nbsp;Stripped Girl ONline</h1>
  <hr>
<?
  if($title)
    do_html_heading($title);
}


function display_job_listings()
{
?>

<html>
<head>
<title>Displaying MySQL Data</title>
</head>
<body>


//////connection script



<table>

<?

$sql = "SELECT * FROM jobs";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td>".$row['date']."</td>";
echo "<td>".$row['title']."</td>";
echo "<td>".$row['description']."</td>";
echo "<td>".$row['location']."</td>";
echo "<td>".$row['compensation']."</td>";
echo "<td>".$row['required']."</td>";
echo "<td>".$row['preferred']."</td>";
echo "<td>".$row['notes']."</td>";
echo "</tr>";
}
?>


</table>
</body>
</html>
}



Notice how I changed the last few lines of code here to try and compensate for the error I was getting. Apparently, my solution wasn't the right one.

Same error.

#13 Destruction

Destruction
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 02 October 2006 - 07:30 PM

</html>
}

notice the fact your function closing bracket is outside of php tags?

#14 Hi I Am Timbo

Hi I Am Timbo
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 02 October 2006 - 07:32 PM

You don't want
</table>
</body>
</html>

inside your loop anyway.

#15 ridiculous

ridiculous
  • Members
  • PipPipPip
  • Advanced Member
  • 175 posts

Posted 02 October 2006 - 07:42 PM

Granted, you're a hardcore programming maniac...I'll give you that. So I removed the HTML just to be jive...it looked like this-

<?

function do_jobs_header($title)
{
  // print an HTML header
?>
  <html>
  <head>
    <title><?=$title?></title>
    <style>
      body { font-family: Arial, Helvetica, sans-serif; font-size: 13px }
      li, td { font-family: Arial, Helvetica, sans-serif; font-size: 13px }
      hr { color: #3333cc; width=300; text-align=left}
      a { color: #000000 }
    </style>
  </head>
  <body>
  <img src="jobs.gif" alt="Big Ops" border=0
      align=left valign=bottom height = 55 width = 57>
  <h1>&nbsp;Stripped Girl ONline</h1>
  <hr>
}

<?
function display_job_listings()
{
?>

<html>
<head>
<title>Displaying MySQL Data</title>
</head>
<body>


//////connection script



<?

$sql = "SELECT * FROM jobs";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td>".$row['date']."</td>";
echo "<td>".$row['title']."</td>";
echo "<td>".$row['description']."</td>";
echo "<td>".$row['location']."</td>";
echo "<td>".$row['compensation']."</td>";
echo "<td>".$row['required']."</td>";
echo "<td>".$row['preferred']."</td>";
echo "<td>".$row['notes']."</td>";
echo "</tr>";
}
?>


Still, errors on line 58. Jesus, show me the way!



#16 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 02 October 2006 - 07:54 PM

you dont end your functions.
Move 1st } (just after long line) in php part
and in the end add one more }




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users