/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] MySQL server version for the right syntax to use near ‘,)’ at line 1

Hi experts,

I have this code to add records to MySQL database in a table named main, getting the following error, please help:

[QUOTE]

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 ‘,)’ at line 1
INSERT INTO main (class,subject,chapter) VALUES (,,)Record Added

[/QUOTE]

[code=php]<?php
$con = mysql_connect(“localhost”,”root”,””);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}

mysql_select_db(“quiz”, $con);

$class=””;
$subject=””;
$chapter=””;

extract($_POST);

$sql=”INSERT INTO main (class,subject,chapter) VALUES ($class,$subject,$chapter)”;

// Execute query
if(mysql_query($sql,$con) === false)
{
echo mysql_error() . “<br />$sql”;
}

mysql_close($con);
print “Record Added”;
?>[/code]

Thanks in advance.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 30.2009 — Any values which are not numeric will need to be quoted.
[code=php]
$sql="INSERT INTO main (class,subject,chapter) VALUES ('$class','$subject','$chapter')";
[/code]
Copy linkTweet thisAlerts:
@MindzaiJul 30.2009 — Your input data should be cleaned/escaped too before use. You are currently open to SQL injection.

[Must write a firefox extension with a button I can just click to paste that!]
Copy linkTweet thisAlerts:
@nyt1972authorJul 31.2009 — Thanks, it worked.
×

Success!

Help @nyt1972 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...