Jump to content

Parse error: syntax error, unexpected T_ECHO


Southern Belle

Recommended Posts

Hope someone can help me with the problem. From what I understand the error appears because of missing ; or tag. I don't see anything missing. I could be going blind though... I've been looking at this problem for a while.

 

This is a VERY simple code and feel dumb that I can't find the problem.

 

<?php
$username = "****";	
$password = "********";
$database = "*********";

mysql_connect(localhost, $username, $password);
@mysql_select_db($database);

$result = mysql_query("SELECT * FROM varieties WHERE type = 'vir' ");

WHILE ($row = mysql_fetch_array($result) or die('Error: '.mysql_error () )
	echo $row['variety']."<br>";

mysql_close();
?>

 

This is the error msg I get...

Parse error: syntax error, unexpected T_ECHO line 21

 

Line 21 is, WHILE ($row = mysql_fetch_array($result)  or die('Error: '.mysql_error () )

 

Any suggestions??

 

By the way...

If I remove "die" from WHILE, I get this msg

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

 

OK, I totally removed the die statement and added the braces (I thought they were optional if there was only one statement). So this is what the code looks like now:

 

$result = mysql_query("SELECT * FROM varieties WHERE type = 'vir' ");

WHILE ($row = mysql_fetch_array($result) )
{
	echo $row['variety']."<br>";
}

 

 

I'm getting this error msg:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

 

Just put a semicolon ; after

 

Just place echo statement after

WHILE ($row = mysql_fetch_array($result) or die('Error: '.mysql_error () )

 

into {}

 

[edit]

 

If my post doesnt make sense... do not worry... I'm prolly too sleepy to  write meaningful posts...

You really should put the die statement on the mysql_query statement.

 

I believe that "type" is a reserved word in mysql, so you need to surround it with backticks:

 

<?php
$q = "SELECT * FROM varieties WHERE `type` = 'vir'";
$result = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());
while($row = mysql_fetch_assoc($result))
     echo $row['variety'] . "<br>\n";
?>

 

Yes, braces are optional when there is only one statement.

 

Ken

OK, I totally removed the die statement and added the braces (I thought they were optional if there was only one statement). So this is what the code looks like now:

 

$result = mysql_query("SELECT * FROM varieties WHERE type = 'vir' ");

WHILE ($row = mysql_fetch_array($result) )
{
	echo $row['variety']."<br>";
}

 

 

I'm getting this error msg:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

 

that error msg is telling you that your query is no good .. check the spelling of your table and field.

Archived

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

×
×
  • Create New...

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.