Forum Moderators: coopster

Message Too Old, No Replies

error message

         

kerspink

7:07 pm on Mar 21, 2008 (gmt 0)

10+ Year Member




Parse error: syntax error, unexpected $end in /home/#*$!#*$!/home/fmys2.php on line 30

can anyone tell me what this means
in this script

<?php

$host = 'localhost';
$user = '#*$!#*$!';
$pass = '#*$!#*$!x';
mysql_connect($host, $user, $pass);

mysql_select_db('$user');
$result = mysql_query("SELECT * FROM books");

if(!$result) die("Query Failed.");

while($row = mysql_fetch_row($result)) {

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
<title>first mysql php action</title>
</head>
<body>
<?php echo "$result"
?>
</body>
</html>

eelixduppy

7:12 pm on Mar 21, 2008 (gmt 0)



Welcome to WebmasterWorld! :)

From what I see here, you do not have a semicolon at the end of the following line:


<?php echo "$result"
?>

And as I see it now, you are not closing your while loop with a closing parenthesis (}).

Also, aside from the error you are receiving, it seems that you aren't properly grabbing the information from the database correctly as you may have wanted. For more information on how to do this properly, please refer to the following thread listed in your library: [webmasterworld.com...]

kerspink

8:50 pm on Mar 21, 2008 (gmt 0)

10+ Year Member



yep redone it but am getting this output

Resource id #3

i would have thougth i would have got a list of titles
i am missing something here

see code
<?php

$host = 'localhost';
$user = 'vvvvvv';
$pass = '#*$!#*$!xx';
mysql_connect($host, $user, $pass);

mysql_select_db($user);
$result = mysql_query("SELECT title FROM books");

if(!$result) die("Query Failed.");

while($row = mysql_fetch_row($result)) {



/*
$row[0] now contains the first column of the current row,
index 1 is the second, etc.
*/
}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
<title>first mysql php action</title>
</head>
<body>
<?php echo "$result"
?>
</body>
</html>

can any one suggest what is missing

eelixduppy

9:39 pm on Mar 21, 2008 (gmt 0)



This is because you are echoing out the resource and not the actually data from the database. The link I gave you above will describe the method of grabbing info from a database in more detail, but as a quick fix you should replace this code:

<?php echo "$result"
?>

With the following:


<?php echo $row['title']; #echoes the title for each row retrieved ?>