getting error in php file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mayanktalwar1988
Forum Contributor
Posts: 133
Joined: Wed Jul 08, 2009 2:44 am

getting error in php file

Post 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
Last edited by Benjamin on Mon Jul 20, 2009 5:17 am, edited 1 time in total.
Reason: Added [code=php] tags.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: getting error in php file

Post by Benjamin »

Can you seem the problem now?
DaiWelsh
Forum Commoner
Posts: 36
Joined: Wed Jan 08, 2003 9:39 am
Location: Derbyshire, UK

Re: getting error in php file

Post 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
Last edited by Benjamin on Mon Jul 20, 2009 5:37 am, edited 1 time in total.
Reason: Changed code type from text to php.
mayanktalwar1988
Forum Contributor
Posts: 133
Joined: Wed Jul 08, 2009 2:44 am

Re: getting error in php file

Post by mayanktalwar1988 »

yes i did what u said daiwelsh..now it is working thanks
Post Reply