Jump to content

Archived

This topic is now archived and is closed to further replies.

xyn

SQL Error

Recommended Posts

Hey Guys!
Can someone tell me what's wrong with my SQL Code, I've checked the code and can't spot an error so it's probably my eyes.

MYSQL_ERROR();
[color=red]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 16[/color]

[code=php:0]mysql_query("INSERT INTO profile (user, age, fav_music, fav_band, fav_song, hat_music, hat_band, hat_song, fir_album, fir_single, fir_gig, interests, stats, rated, date, time) VALUES ('".strtolower($usrnam)."',
'".$_POST[age]."',
'".$_POST[fav_music]."',
'".$_POST[fav_band]."',
'".$_POST[fav_song]."',
'".$_POST[hat_music]."',
'".$_POST[hat_band]."',
'".$_POST[hat_song]."',
'".$_POST[fir_album]."',
'".$_POST[fir_single]."',
'".$_POST[fir_gig]."',
'".$_POST[interests]."',
'".$_POST[stats]."',
'0',
'$date',
'$time'") or die(mysql_error());[/code]

Share this post


Link to post
Share on other sites
I've done it now Lol. mist the connection string...
and a spelling error

Share this post


Link to post
Share on other sites
Try this.

[code]
mysql_query("
INSERT INTO profile
(user, age, fav_music, fav_band, fav_song, hat_music, hat_band, hat_song,
fir_album, fir_single, fir_gig, interests, stats, rated, date, time)
VALUES (
'" .strtolower($usrnam) ."', '$_POST[age]', '$_POST[fav_music]', '$_POST[fav_band]',
'$_POST[fav_song]', '$_POST[hat_music]', '$_POST[hat_band]', '$_POST[hat_song]',
'$_POST[fir_album]', '$_POST[fir_single]', '$_POST[fir_gig]', '$_POST[interests]', '$_POST[stats]', '0', '$date', '$time')"
) or die(mysql_error());
[/code]

Also you should look into addslashes().

Share this post


Link to post
Share on other sites
[quote author=JayBachatero link=topic=99345.msg391205#msg391205 date=1151962950]
Also you should look into addslashes().
[/quote]

...or use MySQL's real_escape_string to prevent injection attacks.

Share this post


Link to post
Share on other sites
$query="INSERT INTO profile (user, age, fav_music, fav_band, fav_song, hat_music, hat_band, hat_song, fir_album, fir_single, fir_gig, interests, stats, rated, date, time) VALUES ('$usrnam','$age','$fav_music','$fav_band','$fav_song','$hat_music','$hat_band','$hat_song','$fir_album','$fir_single],'$fir_gig','$interests','$stats]','0','$date','$time'") or die(mysql_error())";

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.