/    Sign up×
Community /Pin to ProfileBookmark

Buggy MySQL Syntax

Okay, now I’m using INSERT INTO to, guess what?, insert data into my table. But it keeps throwing me errors about syntax, which I just can’t seem to find. Maybe it’s my eyes, so I ask of you, what do you see wrong with the following?

[code=php]
require(“db_connect.php”);
$add=”INSERT INTO comment_mssgs (id, sdate, subject, author, message, views, mt, tid, to) VALUES (”, ‘$cdate’, ‘$subj’, ‘$s_username’, ‘$mssg’, ‘0’, ‘1’, ”, ‘1’)”;
mysql_query($add) or die(“Error: ” . mysql_error());
[/code]

Any help appreciated…

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@solavarMay 04.2004 — Any chance of us seeing the actual error message?
Copy linkTweet thisAlerts:
@MstrBobauthorMay 04.2004 — oops, sorry... forgot to add that... Here you go:


Error: You have an error in your SQL syntax near 'to) VALUES ('', '5/3/2004 18:8:16', 'Test Comment', 'admin', 'This is a test com' at line 1
[/QUOTE]
Copy linkTweet thisAlerts:
@solavarMay 04.2004 — Ah, yes, it is actually the fieldname [B]to[/B] which is the culprit.

It's a reserved word in MySQL so you need to place it in backticks, [B]to[/B]
Copy linkTweet thisAlerts:
@pyroMay 04.2004 — ...Now you know why you should [i]always[/i] enclose the fields in backticks. ?
Copy linkTweet thisAlerts:
@MstrBobauthorMay 04.2004 — MstrBob kneels down before you and worships your wisdom. This is something that MstrBob would never have thought of. Even me HTML-Kit (Which I use for PHP writing, though not execution. It is surprisingly very helpful with syntax highlighting for PHP and has saved me from many an issue with open quotes.) didn't show this to MstrBob. MstrBob is now off to simply change the name of that field. Evidently, MstrBob likes talking about himself in 3rd person...
Copy linkTweet thisAlerts:
@Paul_JrMay 04.2004 — [i]Originally posted by pyro [/i]

[B]...Now you know why you should [i]always[/i] enclose the fields in backticks. ? [/B][/QUOTE]

Y'know, I was wondering that, and I was just about to ask. ?
×

Success!

Help @MstrBob 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.11,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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