-1

我已经倾注了这一点,但找不到可能导致错误的原因。有什么建议么?

$sql = "INSERT INTO users (`id`, `username`, `password`, `firstname`, 
        `lastname`, `photo`, `mobile`, `fax`, `bday`, `homeadd`, `city`,
        `state`, `zip`, `mailingadd`, `altfax`, `altphone`, `email`,
        `emailpass`, `website`, `bio`, `designations`, `photo2`, `type`,
        `confirmed_email`, `registered_on`, `disabled`, `admin_disabled`)
        VALUES (NULL, $username, MD5('$password'), $firstname, $lastname, 
        '', 'test', '', '', '', '', '', '', '', '', '', $email, '', '', '', '',
        '', 'agent', '1', NOW(), $disabled, 0)";`
4

4 回答 4

1

为所有字符串值添加转义。这是 php 函数:mysqli_real_escape_string()。你应该使用PDO重构你的代码

于 2013-06-12T19:40:03.987 回答
0

您的变量仍应使用单引号。每当您插入 a'$variable'时,请在其周围加上单引号。

于 2013-06-12T19:24:32.077 回答
0

您应该在您的个人价值观周围添加引号:

$sql = "INSERT INTO users (id,username,password,firstname,lastname,photo,mobile,fax,bday,homeadd,city,state,zip,mailingadd,altfax,altphone,email,emailpass,website,bio,designations,photo2,type,confirmed_email,registered_on,disabled,admin_disabled) VALUES (NULL, '$username', MD5('$password'), '$firstname', '$lastname', '', 'test', '', '', '', '', '', '', '', '', '', '$email', '', '', '', '', '', 'agent', '1', NOW(), $disabled, 0)";
于 2013-06-12T19:25:00.523 回答
0

您没有引用变量:

$sql       = "INSERT INTO users 
(`id`, `username`, `password`, `firstname`, `lastname`, `photo`, `mobile`, `fax`, `bday`, `homeadd`, `city`, `state`, `zip`, `mailingadd`, `altfax`, `altphone`, `email`, `emailpass`, `website`, `bio`, `designations`, `photo2`, `type`, `confirmed_email`, `registered_on`, `disabled`, `admin_disabled`) VALUES 
(NULL, '$username', MD5('$password'), '$firstname', '$lastname', '', 'test', '', '', '', '', '', '', '', '', '', '$email', '', '', '', '', '', 'agent', '1', NOW(), '$disabled', 0)";   

我真的建议不要使用 mysql_* 函数,因为它们已被弃用并且在未来的版本中将无法使用。如果您使用 PDO 或 MySQLi,则可以使用绑定函数,因此您不必担心引用值。

于 2013-06-12T19:25:38.280 回答