Jump to content

basic SQL troubles


AlanB09

Recommended Posts

hi there, im running the following code to access my database and print out results but keep getting the message:

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/a3866796/public_html/databasetest.php on line 16

 

ive looked through and cant see any errors in my coding.. any suggestions please ?

*i have edited out password/username/server detail for privacy.  *

many thanks

 

<?php

$username="private";

$password="private";

$database="private";

$server="private";

 

$db_handle= mysql_connect($server, $username, $password);

$db_found = mysql_select_db($database, $db_handle);

 

if($db_found) {

 

$SQL="SELCT*FROM tb_a3866796_users";

$result = mysql_query($SQL);

 

 

while ($db_field = mysql_fetch_assoc($result) ) {

print $db_field['ID']."<br>";

print $db_field['username']."<br>";

print $db_field['password']."<br>";

print $db_field['datejoined']."<br>";

}

mysql_close($db_handle);

}

else {

print "Database not Found!";

mysql_close($db_handle);

}

 

?>

Link to comment
Share on other sites

Please use code tags... if you don't know what they are, read the forum rules before posting.

But, I did read your problem and despite the lack of code tags will give you a nudge in the correct direction.

That error message means that the query had an error, hence making the result un-usable to mysql_fetch_assoc(). Try changing your query execution line to this:

  $result = mysql_query($SQL) or die(mysql_error()); 

(btw, the above used code tags)

what that does is say "if mysql_query() returns FALSE because of an error, kill the application and output the error message". Note: mysql_query() will return TRUE if it does not get any results, it will only return FALSE if there is an error in the query.

Link to comment
Share on other sites

**edit** problem solved... check syntax of table name **

 

 

okay to add to this

yup changing the $result code got rid of that error, but now ive got something else lol !

ive looked it up , and tried what i can to sort it.. changing the name and things, but i keep getting this error

 

 Table 'a3866796_users.tb_userlists' doesn't exist 

 

im basically trying to access the table userlists and get a print of the output.  pulling my hair out over here !

 

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.