Jump to content

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");

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.