Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

pyp Code error

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

pyp Code error

Postby zali44 » Tue Oct 23, 2012 2:21 am

Hi everybody,

I am new to pyp. I am working on first php enabled database web page which is giving following error.

Parse error: syntax error, unexpected ';' in E:\inetpub\vhosts\snpet.org\httpdocs\php\index.php on line 34

It seems syntex error. I have consulted all onoline php help to trap error in following code.

$query="SELECT * from news";
$result=mysql_query($query);
#num = mysql_numrows(result);

mysql_close();

echo "<B> News Table data</b> <br>";

$i=0;

while($i < #num) {

$nheading = mysql_result($result,$i,"nheading"); (......line 34)
$ndetail = mysql_result($result,$i,"ndetail");
$ntype= mysql_result($result,$i,"ntype");
$ndate= mysql_result($result,$i,"ndate");
$uploadeddate= mysql_result($result,$i,"uploadeddate");

$i = $i+1;
}
echo "$i Rows listed.";
?>

Can anybody trap the error.

Regards,
zali44
New php-forum User
New php-forum User
 
Posts: 1
Joined: Tue Oct 23, 2012 1:48 am

Re: pyp Code error

Postby seandisanti » Tue Oct 23, 2012 3:02 pm

Remove your mysql_close, that may fix it. additionally, this may be a slightly more readable way to do what you want...


Code: Select all
<?php
$query="SELECT * from news";
$result=mysql_query($query);
echo "<B> News Table data</b> <br>";
$i=0;
while($row=mysql_fetch_assoc($result)) {
   $nheading = $row['nheading'];
   $ndetail = $row['ndetail'];
   $ntype= $row['ntype'];
   $ndate= $row['ndate'];
   $uploadeddate= $row['uploadeddate'];
   $i++;
}
echo "$i Rows listed.";
?>
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: pyp Code error

Postby tkdbb84 » Tue Oct 23, 2012 7:15 pm

its because you have

Code: Select all

while($i < #num) { 
$nheading = mysql_result($result,$i,"nheading");
....


# is the deprecated comment for PHP, so the interpreter sees:

Code: Select all
while($i
$nheading = mysql_result($result,$i,"nheading");


hence an invalid semicolon.
tkdbb84
New php-forum User
New php-forum User
 
Posts: 137
Joined: Tue Mar 08, 2011 9:25 am


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 6 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.