Gossamer Forum
Home : General : Internet Technologies :

PHP sql_query() ...

Quote Reply
PHP sql_query() ...
I seem to be having a bit of a problem with sql_query in a PHP script I'm working on (will be an accounts area for people who have purchased my plugins..so they can login and gt the most upto date version available).

I am using;

Code:
$getmessage = "INSERT INTO `Accounts` (`Name`,`Email`,`Password`,`$item_name`) VALUES ('$first_name','$payer_email','$password','1'";
$result = mysql_query($getmessage);

if (!$result) {
$error = mysql_error();
error("Unable to get details on email account stuff...Reason: $error (code run: $getmessage)", $connection);
}

The query that comes out, is;

INSERT INTO `Accounts` (`Name`,`Email`,`Password`,`MyFaves`) VALUES ('Andrew','andy.newby@ace-installer.com','0.014feEse0.01','1')

But for some reaoson I get an error saying;

Quote:
You have an error in your SQL syntax near '' at line 1

The most weird part of it, is the fact that it will run the printed out SQL query fine via MySQLMan....which makes me come to the conclusion its something to do with the way I'm running it.

Any ideas?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] PHP sql_query() ... In reply to
Do you need all those backticks with PHP?
Quote Reply
Re: [Paul] PHP sql_query() ... In reply to
I got around it with the following code;

$getmessage = "INSERT INTO `Accounts` SET Name = '$first_name', Email = '$payer_email', Password = '$password', $item_name = '1'";

Still a little confused as to why it works in PHPMyAdmin and MySQLMan, but not in my script Frown

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] PHP sql_query() ... In reply to
This will work fine:

Code:
INSERT INTO Accounts (Name,Email,Password,MyFaves) VALUES ('Andrew','andy.newby@ace-installer.com','0.014feEse0.01','1')

As long as your columns are setup properly etc.
Quote Reply
Re: [Paul] PHP sql_query() ... In reply to
Tried that, and it didn't work. I even tried really basic stuff with the VALUES stuff, and it still gave errors Unsure

Doesn't matter too much now though, cos its working Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!