sql error... i think

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

sql error... i think

Post by dull1554 »

Code: Select all

echo "before query";
				$check_query = mysql_query("SELECT * FROM buddies WHERE name='" . $checkmsg[1] . "'") or die(mysql_error());
				echo "after query";
				$check_query_array = mysql_fetch_array($check_query) or die(mysql_error());
				echo "after array";
i know $checkmsg[1] has a value, and the script outputs before query and after query.

it dies during the fetch array call, and no mysql error is outputed
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

At the top of your script, if you haven't already, add

Code: Select all

// troubleshooting purposes only, remove when going 'live'
error_reporting(E_ALL);
ini_set('display_errors', 1);
Also, I'd change your query string to

Code: Select all

$check_query = mysql_query("SELECT * FROM buddies WHERE name='{$checkmsg[1]}'") or die(mysql_error());
If you're going to use double quotes, may as well make use of them.

Also, output the value in $checkmsg with print_r() or var_dump().
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

yea i allready have all error reporting on...

and i tried to change my query to your suggestion but nope
that didnt help either...



ill show u the rest of my code if u want

Code: Select all

<?php
	error_reporting(E_ALL);
	ini_set('display_errors', 1); 
	set_time_limit (0);
     
    require_once "bluetoc/EventHandlers/ObjectBased.php";
    require_once "bluetoc/TocProtocol.php";
    require_once "bluetoc/AimClient.php";
    require_once "bluetoc/MultiplexListener.php";
    
    
    //database connection
	$host = "localhost";
	$user = "******";
	$pswd = "*****";
	$dbname = "*****";
		
	$connect = mysql_connect($host, $user, $pswd)
			or die("Could not connect: " . mysql_error());	
	$database = mysql_select_db("$dbname")
			or die(MySQL_Error());
        
    class offlineBuddyInfoBot extends AimClient
    {
        var $user;
        
        function offlineBuddyInfoBot( $user, $pass )
        {            
            $this->debug_mode   = FALSE;
            $this->aim_user     = $user;
            $this->aim_pass     = $pass;
            
            $this->user = $user;
            
            $this->connect();
        }
        
        // Handle once we've signed on
        function event_sign_on( $args )
        {
            echo "{$this->user}: Yay! I've signed in!\n";
            $this->set_info( "<font face=Georgia>I am powered by BlueTOC (AIM connection class for PHP)</font>" );
        }
        
        // Handle when we get an instant message
        function event_im( $args )
        {
            echo "{$this->user}: {$args['user']} IMed me!\n";
            
            // Remember that AIM IMs usually have HTML
            // so we must strip it so that we can
            // easily parse it
            $message = strip_tags( $args['message'] );
            
            // Let's check if they're telling us to
            // have another time bot sign on
            // The following responds to anyone! If you were to
            // restrict to only some screen names, you would do
            // a check on $args['user']
            if( preg_match( "`^signon ([A-Za-z0-9]+) (.*)$`", $message, $m ) )
            {
                global $listener;
                
                echo "Signing on {$m[1]}\n";
                
                $this->send_im( $args['user'], "<font face=Georgia>Trying to sign on <b>{$m[1]}</b></font>", FALSE );
                $listener->add_client( new offlineBuddyInfoBot( $m[1], $m[2] ) );
                
                return;
            }
            
            
            
            
            
            //exit prog command
			if($message == "please shutdown"){exit;}										
			$checkmsg = array();				
			$checkmsg = explode(" ", $message);
			$checkmsg[0] = strtolower($checkmsg[0]);
			if($checkmsg[0] == "add")
			{
				//add user
				$addmsgtosend = "<font face='Verdana' size=1 color='#006699'>Adding " . $checkmsg[1] . " to our database.</font>";
				$this->send_im($args['user'], $addmsgtosend);
				echo "before query";
				$check_query = mysql_query("SELECT * FROM buddies WHERE name='{$checkmsg[1]}'") or die(mysql_error());
				echo "after query";
				$check_query_array = mysql_fetch_array($check_query) or die(mysql_error());/////heres where the error is!
				echo "after array";
				if($check_query_array['name'] == $checkmsg[1])
				{
					$msgtosend = "<font face='Verdana' size=1 color='#006699'>It appears that " . $checkmsg[1] . " is allready in our database.</font>";
					$this->send_im($args['user'], $msgtosend);
				}
				else
				{				
					$sql_insert = mysql_query("INSERT INTO buddies SET name='" . $checkmsg[1] . "'") or die(MySQL_Error());
					if($sql_insert)
					{
						$this->send_im($args['user'], "<font face='Verdana' size=1 color='#006699'>" . $checkmsg[1] . " was successfully added to our database, you will be able to check " . $checkmsg[1] . "'s buddyinfo within fifteen minutes.</font>");
					}
			
					else
					{
						$dberrormsgtosend = "<font face='Verdana' size=1 color='#006699'>There is currently a problem with our database, please try again soon.</font>";
						$this->send_im($args['user'], $dberrormsgtosend);
					}
				}
				$msgtosend = "<font face='Verdana' size=1 color='#006699'>Thankyou for using OfflineBuddyInfo.  Created and Copywritten by Ryan A Cheeseman.  Contact - Dull1554@gmail.com</font>";
				$this->send_im($args['user'], $msgtosend);							
			}
			elseif($checkmsg[0] == "check")
			{
				#check user
				$checkmsgtosend = "<font face='Verdana' size=1 color='#006699'>Checking " . $checkmsg[1] . ".</font>";//At this moment our interactive buddy info bot is offline.  Check back soon to see if were fully functional!
				$this->send_im($args['user'], $checkmsgtosend);
				$this->get_info($checkmsg[1]);
			}
			else
			{
				#else   In a properly formated message there should be no Puncuation.</font>";
				$elsemsgtosend = "<font face='Verdana' size=1 color='#006699'>Thankyou for using OfflineBuddyInfo.  Created and Copywritten by Ryan A Cheeseman.  Contact - Dull1554@gmail.com</font>";
				$this->send_im($args['user'], $elsemsgtosend);
				$elsemsgtosend1 = "<font face='Verdana' size=1 color='#006699'>To add a Buddy to our database format your message like this, Add InsertBuddyNameHere.</font>";
				$this->send_im($args['user'], $elsemsgtosend1);
				$elsemsgtosend2 = "<font face='Verdana' size=1 color='#006699'>To Check a Buddy's Info while they are offline format your message like this, Check InsertBuddyNameHere.</font>";
				$this->send_im($args['user'], $elsemsgtosend2);
			}
      
            
            
            
            
        }
        
        function event_error( $args )
        {
            // These are a list of errors in English
            // Most, if not all, errors will return an error number
            // and not the error description
            $connection_errors = array(
                100 => 'Data unable to be sent',
                200 => 'Flapon',
                201 => 'Data not received from server after FLAPON packet',
                202 => 'Invalid FLAP SIGNON response from the server',
                203 => 'Invalid response from the server' );
            
            $aim_errors = array (
                0 => 'Success',
                1 => 'AOLIM Error: Unknown Error',
                2 => 'AOLIM Error: Incorrect Arguments',
                3 => 'AOLIM Error: Exceeded Max Packet Length (1024)',
                4 => 'AOLIM Error: Reading from server',
                5 => 'AOLIM Error: Sending to server',
                6 => 'AOLIM Error: Login timeout',
                901 => 'General Error: %s not currently available',
                902 => 'General Error: Warning of %s not currently available',
                903 => 'General Error: A message has been dropped, you are exceeding the server speed limit',
                950 => 'Chat Error: Chat in %s is unavailable',
                960 => 'IM and Info Error: You are sending messages too fast to %s',
                961 => 'IM and Info Error: You missed an IM from %s because it was too big',
                962 => 'IM and Info Error: You missed an IM from %s because it was sent too fast',
                970 => 'Dir Error: Failure',
                971 => 'Dir Error: Too many matches',
                972 => 'Dir Error: Need more qualifiers',
                973 => 'Dir Error: Dir service temporarily unavailble',
                974 => 'Dir Error: Email lookup restricted',
                975 => 'Dir Error: Keyword ignored',
                976 => 'Dir Error: No keywords',
                977 => 'Dir Error: Language not supported',
                978 => 'Dir Error: Country not supported',
                979 => 'Dir Error: Failure unknown %s',
                980 => 'Auth Error: Incorrect nickname or password',
                981 => 'Auth Error: The service is temporarily unavailable',
                982 => 'Auth Error: Your warning level is too high to sign on',
                983 => 'Auth Error: You have been connecting and disconnecting too frequently. Wait 10 minutes and try again. If you continue to try, you will need to wait even longer.',
                989 => 'Auth Error: An unknown signon error has occurred %s' ); 
                
            // Let's see what kind of error we are faced with
            switch( $args['type'] )
            {
                // Connection error
                case ERROR_CONNECTION:
                    echo "* Connection error: {$connection_errors[$args['number']]} ({$args['number']})\n";
                    break;
                // AIM is giving us an error
                case ERROR_AIM:
                    echo "* AIM error: {$aim_errors[$args['number']]} ({$args['number']})\n";
                    break;
            }
        }
    }
    
    $listener = new MultiplexListener;
    $listener->add_client( new offlineBuddyInfoBot( 'offlinebuddyinfo', '******' ) );
    $listener->run();
?>
matt1019
Forum Contributor
Posts: 172
Joined: Thu Jul 06, 2006 6:41 pm

Post by matt1019 »

Wow, interesting.... just a quick question:

What project are you working on?

by the looks of the scripts, it provides information on buddies that are offline (?)

but what is the overall project? or is this it?

-Matt
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

yep, its a site, and AIM bot called OfflineBuddyInfo. Im coding it mostly using some pretty modified versions of the BlueTOC TOC class. i was intended for me to be able to view my friends info while they are offline but its turned into much more then that. im working it on the basis of this, for me to catolog and constantly updat every aim users profile would be impossiable and insane. so im working on setting up this aim bot to allow a person to send it a message to add a user to my database.. i allready have a cron job running that every 30 minutes that updates the profiles in the database assuming they are online, online status is updated every 5 minutes(this my change when the script cant run in less then 5 minutes) using code that i posted here
viewtopic.php?t=51212.
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

so yea... back to the original topic of this post, the error... ive changed those few lines a bit to try and get it to work.....

Code: Select all

echo "before query";
$check_query = mysql_query("SELECT name FROM buddies WHERE name='" . $checkmsg[1] . "'") or die(mysql_error());
echo "after query";
$check_query_array = mysql_num_rows($check_query) or die(mysql_error());
echo "after array";
if($check_query_array != 0)
{
	$msgtosend = "<font face='Verdana' size=1 color='#006699'>It appears that " . $checkmsg[1] . " is allready in our database.</font>";
	$this->send_im($args['user'], $msgtosend);
}
im running this script from the php console, when it dies it doesnt output any errors at all, it just sends me back to

php>
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

it outputs before query and after query, but it dosnt output after array..


so the error is there somewhere...
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

dull1554 wrote:it outputs before query and after query, but it dosnt output after array..
so the error is there somewhere...
What version of PHP are you using?
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

5.1.4, apache 2 and i get some version of perl running too.... the version number eludes me
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

OK I've really no idea, your code looks fine to me.
Here's some stuff you can try:
  • Run the queries that you are running in your code there in a separate test file
    • If that shows the same problem try running those queries in a MySQL console and post the PHP here
    • If that doesn't show the same problem start adding your buggy code to your test script. Use a binary chop to do this, that is, do half first, then halves of that all the time isolating the bug into ever smaller chucks of code. Of course that will take a long time.
  • Specify the optional link identifiers on your mysql_ function calls
  • Try rewriting the application using Mysqli instead
  • Replace "before query", "after query" and "after array" with "echo mysql_info();", see if that gives any clues and post output here.
  • Search the PHP bug database for reports of this behaviour
Sorry I can't be of more help
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

no, no need to apoligize... i just need to stop beating my head up against a brick wall... im kinda glad you, and no one else sees any errors... that just means im not going blind or really starting to stink at what i do..... you mentioned mysqli i know that i have that extension installed but ive never used it before, is it similar?
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Very.
Improved in lots of ways. If you use the OO version you'll be a better programmer for it. I particularly love the data_seek on the mysqli_result objects, that lets you query a whole load of stuff and then get it back in any order you like.

mysqli in the php manual
Post Reply