Jump to content

Table doesn't exist in certain function


perpl3x3d

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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").

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.