/    Sign up×
Community /Pin to ProfileBookmark

You have an error in your SQL syntax

I get this error

Error: 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 ‘Condition, Othercomments) VALUES (”,”,”,”,”)’ at line 1

When I submit a form that activates this code:

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

mysql_select_db(“usedgam_Gamelist”, $con);
$sql=”INSERT INTO Information (Name, Game, Description, Condition, Othercomments)
VALUES
(‘$_POST[name]’,’$_POST[game]’,’$_POST[description]’,’$_POST[condition]’,’$_POST[othercomments]’)”;

if (!mysql_query($sql, $con))
{
die(‘Error: ‘ . mysql_error());
}
echo “1 record added”;

mysql_close($con)
?>[/code]

Also, on an unrelated note, I was wondering if I could get help on a code that automatically puts everything on that database to a web page.

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@stephan_gerlachOct 03.2008 — Not entirely sure what the problem is but simply echo the $sql and see what that displays. I am sure you will find the error that way
Copy linkTweet thisAlerts:
@StripedTigerauthorOct 03.2008 — I'm not sure what you mean by that, I'm pretty new at PHP, but if you mean put echo before the line with $sql, it just gives me:

INSERT INTO Information (Name, Game, Description, Condition, Othercomments) VALUES ('','','','','')
Copy linkTweet thisAlerts:
@Phill_PaffordOct 03.2008 — Doesn't look like you validating your $_POST values when doing the insert.

Learn to validate before it's too late

Little Bobby Tables
Copy linkTweet thisAlerts:
@ariellOct 03.2008 — The your $POSTs are either EMPTY or (depending on your server and php release) you'll need to stick with something like:
[code=php]
$sql="INSERT INTO Information (Name, Game, Description, Condition, Othercomments)
VALUES
('".$_POST['name']."','".$_POST['game']."','".$_POST['description']."','".$_POST['condition']."','".$_POST['othercomments']."')";
[/code]


Check it out.
Copy linkTweet thisAlerts:
@StripedTigerauthorOct 03.2008 — No luck with that code.
Copy linkTweet thisAlerts:
@Phill_PaffordOct 03.2008 — are you just running the script or are you actually posting to it?

to test this just replace all the POSTS with static values

[CODE]
$sql="INSERT INTO Information (Name, Game, Description, Condition, Othercomments)
VALUES
('test_name','test_game','test_desc','test_cond','test_other')";
[/CODE]


just to make sure its working
Copy linkTweet thisAlerts:
@StripedTigerauthorOct 03.2008 — I removed Condition and Othercomments from everything, and that seemed to do the trick. Condition was a drop down menu, do you think that would have been the problem?
×

Success!

Help @StripedTiger 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 5.4,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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