Jump to content

Archived

This topic is now archived and is closed to further replies.

ridiculous

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

Recommended Posts

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>';

?>

Share this post


Link to post
Share on other sites
Also, do Dreamweaver or PHP Eclipse have native debugging utilities that automatically resolve or better describe the cause of these kinds of errors?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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>

}


Share this post


Link to post
Share on other sites
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>";
[color=limegreen]}
?>


</table>
</body>
</html>
}
[/color]


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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
you dont end your functions.
Move 1st } (just after long line) in php part
and in the end add one more }

Share this post


Link to post
Share on other sites

×

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.