Jump to content

[SOLVED] Displaying Data


konetch

Recommended Posts

I have a contant form that submits some quotes into my database. To display the quotes from the database I have written a little code.

 

<html>
<body>
<?
mysql_connect ("localhost","root");
mysql_select_db ("cms");

$sql = "select * from mohdatabase";
$result = mysql_query ($sql);

while ($row = mysql_fetch_array($result))
{
$field1= $row["pageid"];
$field2= $row["quote"];
$field3= $row["author"];

echo "$field1<br>";
echo "$field2<br>";
echo "$field3<p>";

}
?>
</body>
</html>

 

When I look at the page that this is on it shows the error

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\konetcms\test\a\display.php on line 10

 

Would you know why? Thanks, I'm still new and couldn't find an answer.

 

Alex

Link to comment
https://forums.phpfreaks.com/topic/164885-solved-displaying-data/
Share on other sites

Okay I changed it to

 

<html>
<body>
<?
mysql_connect ("localhost","root");
mysql_select_db ("cms");

$sql = "select * from mohdatabase";
$result = mysql_query ($sql);

while ($row = mysql_fetch_array($result)) or die(mysql_error());
{
$field1= $row["pageid"];
$field2= $row["quote"];
$field3= $row["author"];

echo "$field1<br>";
echo "$field2<br>";
echo "$field3<p>";

}
?>
</body>
</html>

 

Is that correct. Now it says there is a parse error on line 10

 

Thanks

Since everything else seems to be fine, assuming there is no password for the user root, try editing your Line 4 to

 

mysql_connect ("localhost","root","");

 

If you have set a password for user root, it should be something like this

 

mysql_connect ("localhost","root","password");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.