Page 1 of 1

getting error in php file

Posted: Mon Jul 20, 2009 5:10 am
by mayanktalwar1988

Code: Select all

<?php
$host = "localhost";
$user = "root";
$pass = "";
$db = "ask";
 
$con = mysql_connect($host,$user,$pass);
mysql_select_db($db,$con);
 
echo "<a href='create_topic.php'>New topic</a>";
echo "<table border='0' width='100%'>
<tr><td width="25%" valign="top">#</td><td="25%" valign="top">Title</td><td="25%" valign="top">Replies</td><td="25%" valign="top">Post Date</td></tr>";
 
$sql = mysql_query("SELECT * FROM topics ORDER BY id DESC");
while($row = mysql_fetch_array($sql)) {
$replies = mysql_num_rows(mysql_query("SELECT * FROM replies WHERE topic_id='".$row['id']."'"));
 
echo "<tr><td>".$row['id']."</td><td><a href='show_topic.php?id=".$row['id']."'>".htmlentities($row['title'])."</a></td><td>".$replies."</td><td>".date("j/n - y",$row['date'])."</td></tr>";
}
 
echo "</table>";
mysql_close($con);
?>
 




error is this

Parse error: syntax error, unexpected T_LNUMBER, expecting ',' or ';' in C:\xampp\htdocs\bho\index.php on line 12

Re: getting error in php file

Posted: Mon Jul 20, 2009 5:17 am
by Benjamin
Can you seem the problem now?

Re: getting error in php file

Posted: Mon Jul 20, 2009 5:30 am
by DaiWelsh
You have mixed and matched quote types and as a result have a clash. You open the PHP string with " then use both ' and " in your html. The first " in the html terminates the php string and the following html is seen as PHP and generates an error. Either escape the quotes or better be consistent in which type of quote you use in the html e.g.

Code: Select all

echo "<table border='0' width='100%'>
<tr><td width=\"25%\" valign=\"top\">#</td><td=\"25%\" valign=\"top\">Title</td><td=\"25%\" valign=\"top\">Replies</td><td=\"25%\" valign=\"top\">Post Date</td></tr>";
or better

Code: Select all

echo '<table border="0" width="100%">
<tr><td width="25%" valign="top">#</td><td="25%" valign="top">Title</td><td="25%" valign="top">Replies</td><td="25%" valign="top">Post Date</td></tr>';
so that the html always uses " and the PHP string is delimited by '

HTH,

Dai

Re: getting error in php file

Posted: Mon Jul 20, 2009 5:49 am
by mayanktalwar1988
yes i did what u said daiwelsh..now it is working thanks