Page 1 of 1

Parse Error Help

Posted: Wed Apr 21, 2004 8:11 pm
by drumminlogan
I am writing my first PHP script with mysql. I am new to PHP and am wondering if you can help me out. I wrote a little form that added information to my database in a table I created. I want to write a script just to view each entry and I get a parse error when I try to run it and can't figure out what the problem is. It says it is on line 78, which is right after {$row['longdescription']}<br /></p>"; This is a modified script from the book PHP for the World Wide Web by Larry Ullman. Thanks.
<?php
if ($dbc=mysql_connect ("localhost", "truthd_logan", "MYPASSWORD")) {
if (!@mysql_select_db ('truthd_123christian'))
{
die ('<p>Could not select the database because: <b>'. mysql_error() . '</b></p>');
}
} else {
die ('<p>Could not connect to MYSQL because: <b>' . mysql_error() . '</b></p>');
}

$query = 'SELECT * FROM 123_listings ORDER BY id DESC';

if ($r = mysql_query ($query))

while ($row = mysql_fetch_array ($r)) {
print "<p><h3>{$row['businessname']}</h3>
{$row['id']}<br />
{$row['webaddress']}<br />
{$row['firstname']}<br />
{$row['lastname']}<br />
{$row['category']}<br />
{$row['shortdescription']}<br />
{$row['longdescription']}<br /></p>";
}
} else {
die ('<p>Could not retrieve the date because: <b>' . mysql_error() . "</b>. The query was $query.</p>");
}

mysql_close();

?>

Posted: Wed Apr 21, 2004 8:16 pm
by John Cartwright

Code: Select all

<?php
if ($dbc=mysql_connect ("localhost", "truthd_logan", "MYPASSWORD")) { 
if (!@mysql_select_db ('truthd_123christian')) 
{ 
die ('<p>Could not select the database because: <b>'. mysql_error() . '</b></p>'); 
} 
} else { 
die ('<p>Could not connect to MYSQL because: <b>' . mysql_error() . '</b></p>'); 
} 

$query = 'SELECT * FROM 123_listings ORDER BY id DESC'; 

if ($r = mysql_query ($query)) {

while ($row = mysql_fetch_array ($r)) { 
print "<h3>$row['businessname']</h3> <br />
                 $row['id']<br /> 
                 $row['webaddress']<br /> 
                 $row['firstname']<br /> 
                 $row['lastname']<br /> 
                 $row['category']<br /> 
                 $row['shortdescription']<br /> 
                 $row['longdescription']<br />"; } else { 
die ('<p>Could not retrieve the date because: <b>' . mysql_error() . "</b>. The query was $query.</p>"); 
} 
}
mysql_close(); 


?>
your missing a { here: if ($r = mysql_query ($query))

i cleaned up ur code a lil too

Posted: Wed Apr 21, 2004 8:22 pm
by drumminlogan
That helped. I found the problem. Had an extra }

Thanks.

Posted: Wed Apr 21, 2004 8:22 pm
by Unipus

Code: Select all

if ($r = mysql_query ($query))
should be

Code: Select all

if ($r = mysql_query ($query)) 
{

Posted: Wed Apr 21, 2004 8:23 pm
by Unipus
You don't have an extra }. You have too few {.

Posted: Wed Apr 21, 2004 8:24 pm
by drumminlogan
That's what I meant. Thanks for the help. It works now.