2012-02-27 17 views
4

エラーメッセージが表示されても、これを動作させることはできません。バッククォートとMySQLのクエリが失敗する理由

エラー

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 

コード

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', '[email protected]', 'awd', '21/05/1990','0','2', 
     '0','4306','Sandnes','0','user','0','0','$image','0','0','0','$time', 
     '$time','0')") 
or die(mysql_error()); 

答えて

9

サラウンドe-mail ...

`e-mail`, 

あなたがそうでなければそこ-を削除することはできません。

+0

ある - また、私が見つけますそのようなエラーが発生した場合、クエリを複数の行に分割します(例:テキストの行ごとに1つの列)。そして、行番号は私のエラーを解決するためにより有効です。 – jbnunn

2

- あなたはこのいけないためにPHPを使用している場合、符号は、変数arroundの単一引用符を使用し、彼らが文句を言わない、すなわち `電子mail``バッククォートで電子メールをラップする必要が

0

、SQLの予約シンボルです解析される。

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

OPは二重引用符を使用しています。 – alex

+0

実際には、SQLクエリの二重引用符は、ansi sql – zerkms

+0

によるフィールド/テーブル名(バックティック)のため、単一ではありません。そして、2つのmysqlはansi sqlを標準的に使用していません –

1

親指のルール:バッククォートの列名と可読性のための文字列変数を連結、MySQLの日付形式は正しいですはYmd(1990年5月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."', '[email protected]', 'awd', '1990-05-21','0','2', 
    '0','4306','Sandnes','0','user','0','0','".$image."','0','0','0','".$time."', 
    '".$time."','0')") 
or die(mysql_error()); 
関連する問題