perpl3x3d Posted December 14, 2009 Share Posted December 14, 2009 Here's the problem! I'm using the following query: SELECT LOCATE('friend', 'friend, ') FROM users.pending_friends_name It is returning this error: Table 'users.pending_friends_name' doesn't exist. I use the same exact query in another function. My Database is called filefind The table in question is called users and the field is called pending_friends_name All of those are lowercase, I've tried editing around the command for case sensitivity, but again it works in a function just below the function in question. It's probably something entirely stupid I'm just looking over, but any help or ideas would be appreciated! PHP ver 5.2.11 My MySQL version is 5.0.51a Using Microsoft's IIS ver 7.0.6000.16386 Vista 6.0.6002 phpMyAdmin 3.2.3 Quote Link to comment https://forums.phpfreaks.com/topic/185144-table-doesnt-exist-in-certain-function/ Share on other sites More sharing options...
Mchl Posted December 14, 2009 Share Posted December 14, 2009 Why not just use SELECT LOCATE('friend', 'friend, ') or for that matter SELECT 1 The result will be the same. Quote Link to comment https://forums.phpfreaks.com/topic/185144-table-doesnt-exist-in-certain-function/#findComment-977348 Share on other sites More sharing options...
perpl3x3d Posted December 14, 2009 Author Share Posted December 14, 2009 I'm using a php variable for the latter half of the locate. So the variable will possibly be different per user. So in PHP it's saying this: $q = "SELECT LOCATE('$from_user', '$end') FROM users.pending_friends_name"; $begin_grab = $this->query($q) or die(mysql_error()); Sorry for not including that earlier. Quote Link to comment https://forums.phpfreaks.com/topic/185144-table-doesnt-exist-in-certain-function/#findComment-977351 Share on other sites More sharing options...
Mchl Posted December 14, 2009 Share Posted December 14, 2009 You are still comparing two strings. You do not use any fields from the table. Anyway, if table is called users, it should be FROM users Quote Link to comment https://forums.phpfreaks.com/topic/185144-table-doesnt-exist-in-certain-function/#findComment-977354 Share on other sites More sharing options...
perpl3x3d Posted December 14, 2009 Author Share Posted December 14, 2009 The two variables depend on the user, so it's called and it varies when called depending on which user is logged in. The other variable depends on a field in the users profile, so it does change. Here is the entire function function removeFriendRequest($from_user, $to_user){ $grab_pending = $this->getUserInfo($to_user) or die("Friend Reequest Fatal Error"); $end=$grab_pending['pending_friends_name']; $q = "SELECT LOCATE('$from_user', '$end') FROM USERS.PENDING_FRIENDS_NAME"; $begin_grab = $this->query($q) or die(mysql_error()); $user_len = strlen($from_user); $user_len = $user_len + 2; if($begin_grab==0) { $q="SELECT SUBSTR(pending_friends_name, '$user_len') FROM USERS.PENDING_FRIENDS_NAME"; $newstring = mysql_query($q, $this->connection) or die(mysql_error()); } else{ { $q="SELECT SUBSTR(pending_friends_name, '0' '$begin_grab') FROM USERS.PENDING_FRIENDS_NAME"; $beginstring = mysql_query($q, $this->connection); $grab_after = $begin_grab + $user_len; $q="SELECT SUBSTR(pending_friends_name, '$grab_after') FROM USERS.PENDING_FRIENDS_NAME"; $endstring = mysql_query($q, $this->connection); $newstring = $beginstring."".$endstring; } if($newstring){ $q="UPDATE ".TBL_USERS." SET pending_friends_name = '$newstring' WHERE username = '$from_user'"; mysql_query($q, $this->connection); } } } Just using users works, but why does the same exact statement work in a function just above this function? I'm not switching between any databases in this file... Quote Link to comment https://forums.phpfreaks.com/topic/185144-table-doesnt-exist-in-certain-function/#findComment-977355 Share on other sites More sharing options...
roopurt18 Posted December 14, 2009 Share Posted December 14, 2009 The FROM clause expects a table name; you're giving it a column name. Thus the error "table does not exist." Quote Link to comment https://forums.phpfreaks.com/topic/185144-table-doesnt-exist-in-certain-function/#findComment-977358 Share on other sites More sharing options...
perpl3x3d Posted December 14, 2009 Author Share Posted December 14, 2009 Well, I'm officially retarded. I now see what you were saying Mchl, it just took me staring at the function for a little while for me to figure it out! Thank you roopurt18 for pointing that out as well. I looked into the other function I said was working, turns out it wasn't, I just didn't know because I didn't tell it to die if it got no result from the query. Thank you for the help! Quote Link to comment https://forums.phpfreaks.com/topic/185144-table-doesnt-exist-in-certain-function/#findComment-977371 Share on other sites More sharing options...
roopurt18 Posted December 15, 2009 Share Posted December 15, 2009 Well, I'm officially retarded. This occurs a lot in programming. Also, there is a tutorial somewhere from the main page about why or die() is bad. I suggest you read it before you use it all over the place. Quote Link to comment https://forums.phpfreaks.com/topic/185144-table-doesnt-exist-in-certain-function/#findComment-977404 Share on other sites More sharing options...
perpl3x3d Posted December 15, 2009 Author Share Posted December 15, 2009 Most definitely, I only use it while the site is in testing stages for troubleshooting. Quote Link to comment https://forums.phpfreaks.com/topic/185144-table-doesnt-exist-in-certain-function/#findComment-977408 Share on other sites More sharing options...
roopurt18 Posted December 15, 2009 Share Posted December 15, 2009 You would be much better off if you did the following: 1) Called set_error_handler() and created your own error handling function that logs to a file, errors.txt or errors.log. I find it handy to keep a static array within this function and ignore duplicate error messages. 2) Create a top level exception handler that does the following: i) Generates a unique ID based off the timestamp and some other criteria ii) Logs the exception message and unique ID to errors.txt (or errors.log) with the additional text "FATAL EXCEPTION" so that you know it was an exception. iii) Display a generic message to the user: "Your request has resulted in an internal error. Contact technical support with the following error ID $erroridgoeshere or try again." Then when you write code, instead of using or die() you can just throw Exceptions. When testing your application if you see your generic error screen, you can check the errors.txt for the related ID and see how / why your code failed. Additionally you don't have to remember to remove or comment out potentially dangerous or die() statements. Your exception handling mechanism can actually just be left in place. Your users won't be presented with information they can abuse and you'll be left with useful logging you can track on going problems with (such as "Is my database connection constantly failing"). Quote Link to comment https://forums.phpfreaks.com/topic/185144-table-doesnt-exist-in-certain-function/#findComment-977431 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.