divinedesigns1 Posted July 11, 2012 Share Posted July 11, 2012 hey im getting an error and i dont seem to know how to fix it, its in the query itself that much i know, i been trying to fix it but nothing is working at the momentthis is the code function user_data(){$args = func_get_args();$fields = '`' .implode('`, `', $args) . '`';$query = mysql_query("SELECT $fields FROM `users` WHERE `user_id`=".$_SESSION['user_id']);$query_result = mysql_fetch_assoc($query);foreach($args as $fields){ $args[$fields] = $query_result[$fields];} this is the query im using $query = mysql_query("SELECT $fields FROM `users` WHERE `user_id`=".$_SESSION['user_id']); is that query wrong? because i dont seem to be able to get this piece working, anything else i fixed in a few mins, but this is just annoying Link to comment Share on other sites More sharing options...
thescientist Posted July 11, 2012 Share Posted July 11, 2012 what's the error? Link to comment Share on other sites More sharing options...
divinedesigns1 Posted July 11, 2012 Author Share Posted July 11, 2012 Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/14/8709614/html/phpalbums/func/user.func.php on line 15since its a mysql_fetch_assoc(); it means the mysql_query is incorrect somewhere along the line, but i dont know whereeeee Link to comment Share on other sites More sharing options...
Guest So Called Posted July 11, 2012 Share Posted July 11, 2012 add: echo $query; as debug code. Link to comment Share on other sites More sharing options...
divinedesigns1 Posted July 11, 2012 Author Share Posted July 11, 2012 yup as i though, the query is wrong somewhere along the line Link to comment Share on other sites More sharing options...
Guest So Called Posted July 11, 2012 Share Posted July 11, 2012 I've often found queries that failed because the variable data being stuffed into them was wrong or null. My latest practice is to generate every query string before doing the actual access, and save the string in an array of all query strings used in the script. Then when I'm logged in as administrator a final part of my footer generation code echoes all the query strings as HTML comments. I can view source to see the actual data used in queries. (Actually I can also turn this feature on or off. This is of course mature code, and I use the feature when I'm maintaining the site or adding new functionality.) Whenever you have a problem with a query containing variables you should take debug steps to learn exactly how the variable data is being filled into the query. If it's still a problem you can cut and paste the exact query, and run it manually in phpMyAdmin and possibly get new insight and new error indications that show why your query fails. Link to comment Share on other sites More sharing options...
divinedesigns1 Posted July 12, 2012 Author Share Posted July 12, 2012 this is giving me a dam headache, still isnt working, echoing it out, print_r(), and var_dump(), keep getting bool(false). okie im totally lost on this one hahahahaha Link to comment Share on other sites More sharing options...
birbal Posted July 12, 2012 Share Posted July 12, 2012 why dont you print it? Link to comment Share on other sites More sharing options...
divinedesigns1 Posted July 12, 2012 Author Share Posted July 12, 2012 i did, nothing showed up, and then i did a var_dump and i got a bool(false) its just the query thats not working im going to break it apart to see which part is actually causing a problem Link to comment Share on other sites More sharing options...
birbal Posted July 12, 2012 Share Posted July 12, 2012 you are printing the result resource and as it is false, it wont print you anything. you should print the query itself to analize that. Link to comment Share on other sites More sharing options...
divinedesigns1 Posted July 12, 2012 Author Share Posted July 12, 2012 you are printing the result resource and as it is false, it wont print you anything. you should print the query itself to analize that. not really im actually printing the query, im getting bool(false) after i add the $_SESSION() function so i have to figure out how to use the session() function within the query to make it work Link to comment Share on other sites More sharing options...
birbal Posted July 12, 2012 Share Posted July 12, 2012 there is not any php function like session() or $_SESSION(). can you post your updated code? Link to comment Share on other sites More sharing options...
php_developer Posted July 12, 2012 Share Posted July 12, 2012 first print $fields variable and get its value and then place that actual value in the query at place of $fields after that copy the whole query in phpmyadmin and run this query. you'll definately get the answer Link to comment Share on other sites More sharing options...
divinedesigns1 Posted July 12, 2012 Author Share Posted July 12, 2012 the problem is fixed, it was that the function which allows you to insert the data into the database did not work and still doesnt work, so that have to be fixed Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now