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
https://forums.phpfreaks.com/topic/185126-basic-sql-troubles/
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
https://forums.phpfreaks.com/topic/185126-basic-sql-troubles/#findComment-977256
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
https://forums.phpfreaks.com/topic/185126-basic-sql-troubles/#findComment-977279
Share on other sites

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.