Skip to main content
Harm_Millaard
Inspiring
June 10, 2011
Answered

Parse error: syntax error, unexpected T_VARIABLE in line 47.

  • June 10, 2011
  • 1 reply
  • 1218 views

Using phpmyadmin I created a simple query and had the program create the php code, which reads like this:

$sql  = 'SELECT *FROM `Personal_data` WHERE 1  ORDER BY `Date & Time` ASC LIMIT 0, 30 ';

I copy/paste that statement into my code, parts of it are:

44. $con = mysql_connect($localhost, $user, $password);
45. $db = mysql_select_db($database) or die( "Unable to select database");
46. $br = "<br />"
47. $sql = 'SELECT *FROM `Personal_data` WHERE 1 ORDER BY `Date & Time` ASC LIMIT 0, 30 ';
48. $result = mysql_query($sql);
49. while($row = mysql_fetch_array($result))
50.   {  echo $row['Ref_ID'] . " " . $row['Date & Time'] . " " . $row['IP_Address'] . " " . $br;  }
51. mysql_free_result($result); 
52. mysql_close($con);
53. ?>

Why do I get this Parse error in this bold line?

This topic has been closed for replies.
Correct answer

Look on line 46

46. $br = "<br />"

You need to add a semi-colon

46. $br = "<br />";

Gary

1 reply

Correct answer
June 10, 2011

Look on line 46

46. $br = "<br />"

You need to add a semi-colon

46. $br = "<br />";

Gary

Harm_Millaard
Inspiring
June 10, 2011

Gary,

Duuhh, what a stupid mistake, but you saw it immediately. Thanks a lot.

Next question if I may. I can see my table, but want to add a calculated field to the table and sort on it.

I made this code, with your correction of course:

$con = mysql_connect($localhost, $user, $password);
$db = mysql_select_db($database) or die( "Unable to select database");
$br = "<br />";
$sql = 'SELECT *FROM `Personal_data` WHERE 1 ORDER BY `Date & Time` ASC LIMIT 0, 500 ';
$result = mysql_query($sql);

echo "<table border='1'>
<tr>
<th>Date & Time</th>
<th>Email</th>
<th>Computer ID</th>
<th>Model CPU</th>
<th>Clock speed</th>
<th>RAM installed</th>
<th>Version</th>
<th>Graphics card</th>
<th>Total score</th>
<th>Disk I/O</th>
<th>MPEG2-DVD</th>
<th>H.264-br</th>
<th>MPE On</th>
<th>MPE Off</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['Date & Time'] . "</td>";
  echo "<td>" . $row['Email'] . "</td>";
  echo "<td>" . $row['Computer ID'] . "</td>";
  echo "<td>" . $row['Model CPU'] . "</td>";
  echo "<td>" . $row['Clock speed'] . "</td>";
  echo "<td>" . $row['RAM installed'] . "</td>";
  echo "<td>" . $row['Version'] . "</td>";
  echo "<td>" . $row['Graphics card'] . "</td>";
  echo "<td>" . $row['Disk I/O'+'MPEG2-DVD'+'H.264-BR'+'MPE On'+'MPE Off'] . "</td>";
  echo "<td>" . $row['Disk I/O'] . "</td>";
  echo "<td>" . $row['MPEG2-DVD'] . "</td>";
  echo "<td>" . $row['H.264-BR'] . "</td>";
  echo "<td>" . $row['MPE On'] . "</td>";
  echo "<td>" . $row['MPE Off'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_free_result($result); 
mysql_close($con);
?>

This works, apart from the highlighted line, which does not show the calculated results, but the primary key. Actually I want to have something, in Excel terms, like:

Sum (Disk I/O, MPEG2-DVD, H.264-BR, (MIN(MPE On, MPE Off))

I assume this is another duuhh experience for me. During my first exercise with PHP I have learnt that interpunction can be devastating. The slightest type is punished. That will take some getting used to, since I come from an APL background, where more than 10 lines of code was extravagant.

June 10, 2011

I'm not sure, perhaps someone with more experience with sql calculations can help, but it seems to me that this:

echo "<td>" . $row['Disk I/O'+'MPEG2-DVD'+'H.264-BR'+'MPE On'+'MPE Off'] . "</td>";

Should be this

echo "<td>" . $row['Disk I/O']+['MPEG2-DVD']+['H.264-BR']+['MPE On']+['MPE Off'] . "</td>";

or perhpas

$calcu = $row['Disk I/O']+$row['MPEG2-DVD']+$row['H.264-BR']+$row['MPE On']+$row['MPE Off'];

echo "<td>". "$calcu" . "</td>";

Gary