Mindez Posted November 25, 2006 Share Posted November 25, 2006 Hey.I'm having trouble with my SQL. Which is probably going to be something very simple that I'm getting wrong. But here goes.A friend of mine made some SQL include files for me, about 2 years ago. And now, when I come to use them, it doesn't seem to work. I've since lost touch with that friend, and I can't get it to work any more.The include file contains:[code] function SQL_GET($table, $section, $id, $idtable) { $db_object = mysql_connect($_ENV['server'], $_ENV['sql_user'], $_ENV['password']); mysql_select_db($_ENV['database'],$db_object); $result = mysql_query("SELECT * FROM $table"); if ($myrow = mysql_fetch_array($result)) { do { if (!$id == 0) { if ($id == $myrow[$idtable]) { $temp = $myrow[$section]; return $temp; } } else { $temp = $myrow[$section]; return $temp; } } while ($myrow = mysql_fetch_array($result)); return "ERROR"; } else { return "ERROR"; } mysql_close($db); }[/code]And the code I'm sending to it:[code]for ( $for=0; $for<=10; $for=$for+1 ) { $datetocheck = mktime(0, 0, 0, date("m"), date("d")-$for, date("Y")); $checkdate = date("Y-m-d", $datetocheck); echo $checkdate; $endgetweekid = SQL_GET(images, weekID, date, $checkdate); echo $endgetweekid;}[/code]But it's just returning:[code]2006-11-25Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\includo\SQL.php on line 41ERROR2006-11-24Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\includo\SQL.php on line 41ERROR2006-11-23Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\includo\SQL.php on line 41ERROR2006-11-22Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\includo\SQL.php on line 41ERROR2006-11-21Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\includo\SQL.php on line 41ERROR2006-11-20Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\includo\SQL.php on line 41ERROR2006-11-19Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\includo\SQL.php on line 41ERROR2006-11-18Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\includo\SQL.php on line 41ERROR2006-11-17Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\includo\SQL.php on line 41ERROR2006-11-16Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\includo\SQL.php on line 41ERROR2006-11-15Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\includo\SQL.php on line 41ERROR[/code](Line 41 is the if ($myrow = mysql_fetch_array($result)) { line)Can anyone see a problem?I'm using MySQL version 4.1.10, etc.Thanks.EDIT: By the way, the weekID for date 2006-11-19 should be '6'.EDIT: The four _ENV variables are defined earlier in the script. Obviously.-Mindez Quote Link to comment https://forums.phpfreaks.com/topic/28469-simple-sql-query-help/ Share on other sites More sharing options...
ravravrav Posted November 26, 2006 Share Posted November 26, 2006 Sorry im a newbie myself; first thing I thought was:where it says --- $result = mysql_query("SELECT * FROM $table");change the $table bit to '$table' ??Might not work but at least thats one thing to cross off lol... Quote Link to comment https://forums.phpfreaks.com/topic/28469-simple-sql-query-help/#findComment-130295 Share on other sites More sharing options...
Mindez Posted November 26, 2006 Author Share Posted November 26, 2006 Thanks for the reply.Nay, didn't work. Same errors and stuff.Thanks anyway. At least I'm not being ignored. :D Quote Link to comment https://forums.phpfreaks.com/topic/28469-simple-sql-query-help/#findComment-130299 Share on other sites More sharing options...
fenway Posted November 26, 2006 Share Posted November 26, 2006 Try adding or die( mysql_error() ) and see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/28469-simple-sql-query-help/#findComment-130324 Share on other sites More sharing options...
Mindez Posted November 26, 2006 Author Share Posted November 26, 2006 [quote author=fenway link=topic=116300.msg473841#msg473841 date=1164505931]Try adding or die( mysql_error() ) and see what happens.[/quote]I'm not quite sure exactly where you want me to add that. I'll have a go though. :DEDIT: Well, I added it like:[quote] if ($myrow = mysql_fetch_array($result) or die(mysql_error())) {[/quote]and it just displays:[quote]2006-11-26Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\includo\SQL.php on line 40You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''images'' at line 1[/quote]('images' is the name of the SQL table.)It doesn't display any more than just the one error.EDIT: However, if I remove the quotes around the $table variable, it just says "No database selected" o_O; Quote Link to comment https://forums.phpfreaks.com/topic/28469-simple-sql-query-help/#findComment-130332 Share on other sites More sharing options...
fenway Posted November 26, 2006 Share Posted November 26, 2006 Well, I actually meant to add it around the mysql_query() call -- and if you get no database selected, then you're missing a select_db() call. Quote Link to comment https://forums.phpfreaks.com/topic/28469-simple-sql-query-help/#findComment-130479 Share on other sites More sharing options...
Mindez Posted November 26, 2006 Author Share Posted November 26, 2006 Thank you, muchly, for this.I had two things wrong. I didn't give my username any privileges in the SQL database (Which was a stupid mistake) and I had "$checkdate" and "date" the wrong way round.Thanks to everyone that helped. I'm glad I got it by myself (With a few hints). Ah, the self-gratification. :) Quote Link to comment https://forums.phpfreaks.com/topic/28469-simple-sql-query-help/#findComment-130636 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.