Jump to content

MySQL error.


3raser

Recommended Posts

My code:

 

$extract = mysql_query("SELECT id,title,message FROM blog ORDER BY id DESC LIMIT 1");
while ($row = mysql_fetch_assoc($extract))
{
echo "<div class='right'><h2>".$row['title']."</h2><div class='articles'>".nl2br(stripslashes($row['message']))."</div></div>";
} 

 

Error:

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/stonedms/public_html/justin/Toplist/index.php on line 29

 

I've double checked my database, and it seems like I've have everything correct.

Link to comment
Share on other sites

can you do

<?php
print_r ($extract); //and paste what you get?
//place at bottom of code below the query

?>

 

Tried that and it doesn't seem to print out anything.

 

<?php

$extract = mysql_query("SELECT id,title,message FROM blog ORDER BY id DESC LIMIT 1");
while ($row = mysql_fetch_assoc($extract))
{
echo "<div class='right'><h2>".$row['title']."</h2><div class='articles'>".nl2br(stripslashes($row['message']))."</div></div>";
}

print_r ($extract);

?>

Link to comment
Share on other sites

Replace

<?php
$extract = mysql_query("SELECT id,title,message FROM blog ORDER BY id DESC LIMIT 1");
?>

with

<?php
$q = "SELECT id,title,message FROM blog ORDER BY id DESC LIMIT 1";
$rs = mysql_query($q) or die("problem with the query: $q<br>" . mysql_error());
$extract = mysql_query($rs);
?>

 

And see if you get an error printed.

 

Ken

Link to comment
Share on other sites

Replace

<?php
$extract = mysql_query("SELECT id,title,message FROM blog ORDER BY id DESC LIMIT 1");
?>

with

<?php
$q = "SELECT id,title,message FROM blog ORDER BY id DESC LIMIT 1";
$rs = mysql_query($q) or die("problem with the query: $q<br>" . mysql_error());
$extract = mysql_query($rs);
?>

 

And see if you get an error printed.

 

Ken

 

problem with the query: SELECT id,title,message FROM blog ORDER BY id DESC LIMIT 1

No database selected

 

Edit:

 

I do have the correct mysql connect information.

Link to comment
Share on other sites

The error says "No Database Selected". Please show the code where you select the DB (remove any connection details like username/password).

 

Ken

 

<?php

session_start();

 

$title = "MCTop";

$description = "The site to find your popular SMP needs!";

 

$mysql_host = "localhost";

$mysql_database = "";

$mysql_user = "";

$mysql_password = "";

 

mysql_connect("$mysql_host", "$mysql_user", "$mysql_password");

mysql_select_db("$mysql_database");

 

?>

Link to comment
Share on other sites

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.