0

hi guys , i wrote this code but when i try to open the page it says there is a syntax error on line 26
here is the code :

<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td>
<strong><h2>Welcome to Our Website</h2></strong>
</td>
</tr>
</table>
<br />
<?
$tbl_name = "posts";
mysql_connect('localhost','username','password')or die("can not connnect to database");
mysql_select_db("$musql_database")or die("sorry , can not sellect db");
$sql="SELECT*FROM $tbl_name";
$result=mysql_query($sql);
while($rows=mysql_fetch_array("$result"))
{
?>
<table width="400" border="0" cellpadding="0" cellspacing="1" bgcolor="#cccccc">
<tr><td>
<table width="400" border="0" cellpadding="2" cellspacing="1" bgcolor="#ffffff">
<tr>
<td>Title : <? echo $rows['title']; ?></td>
</tr>
<tr>
<td>--> <?   echo $rows['post']; ?> </td>
</tr>
</table></td></tr></table>

and this is the error :
Parse error: syntax error, unexpected $end in /www/a/w/a/awah/htdocs/add_email_test/admin/view-posts.php on line 26

this code is to get the post and the title form the database and it view it ,like a blog .

6
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by Shanti C
0

is that the whole code?
in which case you must start with php tags rather than half way down.
just put <?PHP //start php ?>
at the top with no spaces in front.
also your server may not support short tags <? ?> change to <?PHP and ?>
line 12 you have musql instead of mysql, this could be a possible typo
line 13 try putting spaces in your query "SELECT * FROM $tbl_name"


oh actually i read your code properly now and you've forgotten to close your while statement.
put <?PHP } ?> before your end table :)
hope this helps

0

Close the while statement at the end of the table
<?php
}
?>
and avoide using <?//code?> instead try to use <?php //code /?>
cause it may cause some serious problem in some hosts, if allow <? ?> is not un commented in your php.ini file

0

1.sql command select*from >> select * from
2. while($rows=mysql_fetch_array("$result")) >> while($rows=mysql_fetch_array($result))
3. you forget close end for while
try to use <?php } ?> andtheend of html tags.

0

Finally Try with this code :

<?
$musql_database="dbname"; // Give Your DB name also
$tbl_name = "posts";
mysql_connect('localhost','username','password')or die("can not connnect to database");
mysql_select_db("$musql_database")or die("sorry , can not sellect db");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

?><table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td>
<strong><h2>Welcome to Our Website</h2></strong>
</td>
</tr>
</table>
<br />
<?
while($rows=mysql_fetch_array($result))
{
?>
<table width="400" border="0" cellpadding="0" cellspacing="1" bgcolor="#cccccc">
<tr><td>
<table width="400" border="0" cellpadding="2" cellspacing="1" bgcolor="#ffffff">
<tr>
<td>Title : <? echo $rows['title']; ?></td>
</tr>
<tr>
<td>--> <?   echo $rows['post']; ?> </td>
</tr>
</table></td></tr></table>
<? }?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.