Why is my MySQL query not working

I can't get this to work, keep getting the error message.

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 '-mail, password, birth_date, age, sex, profile_text, zip_code, zip_code_state, c' at line 1 

the code

 mysql_query("INSERT INTO users (username, e-mail, password, birth_date, age, sex, profile_text, zip_code, zip_code_state, coins, rank, profile_visits, profile_likes, profile_image, profile_points, activated, deleted, reg_time, last_active_time, reg_ip) VALUES ('$randomName', ' awduhawd@hotmail.com ', 'awd', '21/05/1990','0','2', '0','4306','Sandnes','0','user','0','0','$image','0','0','0','$time', '$time','0')") or die(mysql_error()); 
+4
source share
4 answers

Surround e-mail with reverse windows ...

 `e-mail`, 

Otherwise you cannot leave - .

+9
source

the sign is a reserved character in SQL, it is necessary to wrap e-mail in backlinks, that is, `e-mail`

+2
source

Thumb Rule: Column Names in Inverse Loops and String Variable Concatenation for Readability, MySQL Date Format - Ymd (1990-05-21)

 mysql_query("INSERT INTO users (`username`, `e-mail`, `password`, `birth_date`, `age`,`sex`, `profile_text`, `zip_code`, `zip_code_state`, `coins`, `rank`, `profile_visits`, `profile_likes`, `profile_image`, `profile_points`, `activated`, `deleted`, `reg_time`, `last_active_time`, `reg_ip`) VALUES ('".$randomName."', ' awduhawd@hotmail.com ', 'awd', '1990-05-21','0','2', '0','4306','Sandnes','0','user','0','0','".$image."','0','0','0','".$time."', '".$time."','0')") or die(mysql_error()); 
+1
source

If you use php for this, do not use single quotes around arround variables, they will not be parsed.

 '$randomName' = wrong either use "$randomName" or use "'.$randomName.'" 
0
source

Source: https://habr.com/ru/post/1398718/


All Articles