-1

如何将其插入917678904@tmomail.commysql数据库?.

我尝试在它周围加上单引号而没有单引号,但两种方法都失败了。

// This is my query:

$n = 917678904@tmomail.com;
$table = "invites";

if(!mysql_query("INSERT into $dbname.$table (accepted_by, accepted_on, phone, email,  reffer) 
              VALUES('NULL', 'NULL', 'NULL', `$n`, 'NULL'")){
                 echo mysql_error();
}

这是表结构

accepted_by VARCHAR (50) NOT NULL
accepted_on VARCHAR (45) NOT NULL
phone VARCHAR (11) NULL
email VARCHAR (250) NULL
refferer CHAR (3) NOT NULL)

这是 $n 周围带有单引号的错误消息:

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 2

我正在使用 MYSQL 5.0 版

4

1 回答 1

1
`$n`

in your values field is incorrect. Backticks are used to escape field names, which the value of $n almost certainly isn't. It should be using regular quotes:

INSERT ... VALUES (..., '$n', ...)
                        ^--^--

As well, 'NULL' is also incorrect. That will try to insert the literal characters N, U, L, L into your db table. For an actual SQL null value, remove the quotes:

... VALUES(NULL, NULL,....)
           ^^^^

And lastly, you say your table structure has refferer, but your query string is using reffer. Maybe just a typo, but worth pointing out.

于 2012-12-17T21:30:48.000 回答