PHP & MySql = Query was empty

Hi Guys,

I need some help, when i try to load my Query i keep getting the following message:

Query was empty

I’ve gone over my code and i cant work out why, iv tried to echo the query too but theres nothing showing. Below is my code, can someone see the problem and help me please? Thank you in advance! :slight_smile:


//Add Lead To Database
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Oops theres an error, our highly trained monkeys have been notified.");

$query = sprintf('INSERT INTO leads (ProgramID, ProgramName, AffID, SubID, AdID, ClickIP, LeadIP, Status, Referer, Payout, NetPayout, MerchantPayout, Title, FirstName, LastName, CompanyName, Address1, Address2, City, County, PostCode, Country, Telephone, Mobile, Email Address, TermsAgreed, EmailContact, TelephoneContact, PostContact, UserAgent, IPISP, POFCheck, EmailCheck, IPCheck, UserAgentCheck, FraudCheck, CountryCheck, UniqueID) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)',
			quote_smart($ProgramID),
			quote_smart($ProgramName),
			quote_smart($affid),
			quote_smart($subid),
			quote_smart($adid),
			quote_smart($click),
			quote_smart($ip),
			quote_smart($status),
			quote_smart($referer),
			quote_smart($affpayout),
			quote_smart($netpayout),
			quote_smart($merchantpayout),
			quote_smart($title),
			quote_smart($firstname),
			quote_smart($lastname),
			quote_smart($companyname),
			quote_smart($address1),
			quote_smart($address2),
			quote_smart($city),
			quote_smart($county),
			quote_smart($postcode),
			quote_smart($country),
			quote_smart($telephone),
			quote_smart($mobile),
			quote_smart($emailaddress),
			quote_smart($termsagreed),
			quote_smart($emailcontact),
			quote_smart($telephonecontact),
			quote_smart($postcontact),
			quote_smart($useragent),
			quote_smart($ipisp),
			quote_smart($emailcheck),
			quote_smart($ipcheck),
			quote_smart($useragentcheck),
			quote_smart($fraudcheck),
			quote_smart($countrycheck),
			quote_smart($uniqueid));
			echo $query;
mysql_query($query) or die(mysql_error());
mysql_close();
//End

Just so you know i noticed that i had Email Address instead of EmailAddress in the Query as a field name but have changed that. Still get the error though :frowning:

Two basic things to do in order to debug this – is it PHPs fault or is it an SQL error?

Try and echo $query onto the page and inspect it closely.

Copy that text output and paste it into your db directly, does it work?

Ya also might want to count the number of %s’s, and the number of variables…