a simple syntax problem....

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

a simple syntax problem....

Post by dull1554 »

what for the love of allah is wrong with this line

Code: Select all

$sql_insert = mysql_query("INSERT INTO buddies ('name') VALUES ('" . $checkmsg[1] . "')") or die(MySQL_Error());
TO - ryanacheeseman : Adding ryanacheeseman to our database.You have an error in
your SQL syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near ''name') VALUES ('ryanacheeseman')' at line 1
if anyone wants to see the rest of the script ill post it.... its just an aim bot to gather and insert info into a database.....

i just cant see the stinkin error and its killin me
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 »

Code: Select all

<?php
$nfp="";
include("aimclassw.php");
include("dconnection.php");

$screenName="offlinebuddyinfo";  //aim screen name
$password="*************";    //aim password

//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());


//instantiate class
$b=new Aim($screenName,$password,1);
$b->myServer="toc-m08.blue.aol.com";
$b->myServer="aimexpress.oscar.aol.com";
$b->registerHandler("IMIn","ImINHand");
$b->registerHandler("Rvous","OnRvousIn");
$b->registerHandler("DimIn","onDimIn");
$b->registerHandler("ChatInvite","chatInvite");
$b->registerHandler("ChatIn","chatMessage");
$b->registerHandler("CatchAll","onFallThrough");
$b->signon();
$b->setProfile("",true);



while(1)
{
	$b->receive();
	$b->myLastReceived="";
}

function chatMessage($message)
{
	global $b;
	$info=getMessageInfo($message);
	//@list($cmd, $info['chatid'], $info['user'], $info['whisper'], $info['message']) = explode(":", $command['incoming'],5);
	
	if($info['user'] != $b->getMyScreenName())
	{
		$info['message']=strip_tags($info['message']);
		$b->chatSay($info['chatid'],strrev($info['message']));
	}
}

function chatInvite($message)
{
	global $b;
	$info=getMessageInfo($message);
	$b->joinChat($info['chatid']);
}

function ImINHand($message)
{
	global $b;
	$info=getMessageInfo($message);
	$info['message']=strip_tags($info['message']);
	// $into['from'] contains sender
	// $info['message'] contains message
	//$b->sendIm($info['from'],strrev($info['message']));
							
							
	//exit prog command
	if($info['message'] == "end"){exit;}						
							
							
							
	$checkmsg = explode(" ", $info['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>";
		
		$b->sendIm($info['from'], $addmsgtosend);
		$sql_insert = mysql_query("INSERT INTO buddies ('name') VALUES ('" . $checkmsg[1] . "')") or die(MySQL_Error());
		
		if($sql_insert)
		{
			$b->sendIm($info['from'], "<font face='Verdana' size=1 color='#006699'>Adding " . $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>";
			$b->sendIm($info['from'], $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>";
		$b->sendIm($info['from'], $elsemsgtosend);							
	}
	elseif($checkmsg[0] == "check")
	{
		#check user
		$checkmsgtosend = "<font face='Verdana' size=1 color='#006699'>Checking " . $checkmsg[1] . ".  At this moment our interactive buddy info bot is offline.  Check back soon to see if were fully functional!</font>";
		$b->sendIm($info['from'], $checkmsgtosend);
	}
	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>";
		$b->sendIm($info['from'], $elsemsgtosend);
		$elsemsgtosend1 = "<font face='Verdana' size=1 color='#006699'>To add a Buddy to out database format your message like this, Add InsertBuddyNameHere.</font>";
		$b->sendIm($info['from'], $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>";
		$b->sendIm($info['from'], $elsemsgtosend2);
	}
}

function onRvousIn($message)
{
	global $b;
	global $nfp;
	sEcho($message);
    //@list($cmd,$user,$uuid,$cookie,$seq,$rip,$pip,$vip,$port,$tlvs)=explode(":",$message,10);
	$info=getMessageInfo($message);
	print_r($info);
    if($info['uuid'] == IMAGE_UID)
		$nfp=$b->acceptRvous($info['user'],$info['cookie'],$info['uuid'],$info['vip'],$info['port']);
	else if($info['uuid'] == FILE_SEND_UID)
		$nfp=$b->acceptRvous($info['user'],$info['cookie'],$info['uuid'],$info['vip'],$info['port']);
	else if($info['uuid'] == BUDDY_ICON_UID)
	{
		sEcho("Buddy Icon request");
	}
	//stream_set_timeout($nfp,1);
}

//'VOICE_UID' 
//'FILE_GET_UID'
//'IMAGE_UID'
//'BUDDY_ICON_UID'
//'STOCKS_UID'
//'GAMES_UID'


function onDimIn($message)
{
	global $b;
	if(strlen($message['message'])>0)
	{
		if(strstr($message['message'],"<BINARY>"))
		{
			
		//$b->sendDim($message['message'],$message['from']);
		}
		else
		{	//Send it back??
			$b->sendDim($message['from'],strrev(strip_tags($message['message'])));
		}
	}
	
}

function onFallThrough($message)
{
	sEcho($message);
}

?>
heres the rest of my code..... it uses a class that is openly available on sourceforge called phptoclib, similar to NET::AIM written in perl

i know its sloppy but its kinda nifty to talk to aim with php
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

If you execute the following query directly in MySQL, what happens?

Code: Select all

INSERT INTO buddies ('name') VALUES ('ryanacheeseman')
Probabaly the quotes around the field name.
Last edited by Christopher on Mon Jul 03, 2006 1:51 pm, edited 2 times in total.
(#10850)
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Re: a simple syntax problem....

Post by mattcooper »

Whoops! Unnecessary use of concatenation and single quotes... also, not sure about "buddies ('name')" syntax. Assuming that "buddies" is the tqable and "name" is the column, use:

Code: Select all

mysql_select_db(buddies); // selects the db you want to use
$sql_insert = mysql_query("INSERT INTO name VALUES (' $checkmsg[1] ')") or die(MySQL_Error()); // selects the column you want to query
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 »

thanks for that.........
it gave me a little more error info

and i changed my sytnax to this

Code: Select all

$sql_insert = mysql_query("INSERT INTO buddies SET name='" . $checkmsg[1] . "'") or die(MySQL_Error());
thanks for the slap in the face...what a tired programmer always needs
Post Reply