我试图创建一个从注册表单中收集数据的表,并希望添加几行(zip、state 等)。除了我添加的行之外,代码工作正常(名称、电子邮件、用户名等)。知道为什么其他人会被很好地移动,而最新的条目没有被移动,它们似乎就消失了。
更新:5-2-13 11:07AM EST 提交表单时出错
Error inserting data to the table
query:insert into users(
name,
lastname,
email,
username,
password,
zipcode,
country,
phonenumber,
address,
city,
state,
confirmcode
values
(
"Lucas",
"Weir",
"lucas@12miletechs.com",
"qualitygoods11",
"2aeac48777d7d33ac22cb0c1bac45bf3",
"48178",
"Usa",
"248xxx8851",
"XXXX Hen Rd.",
"South Lyon",
"MI",
"18456d8a76e3337cebb1fec161c50291"
)
mysqlerror: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 'values
(
"Lucas",
"Weir",
"lucas@12miletechs.com",
"qua' at line 14
Inserting to Database failed!
代码:
function CollectRegistrationSubmission(&$formvars)
{
$formvars['name'] = $this->Sanitize($_POST['name']);
$formvars['email'] = $this->Sanitize($_POST['email']);
$formvars['username'] = $this->Sanitize($_POST['username']);
$formvars['password'] = $this->Sanitize($_POST['password']);
$formvars['lastname'] = $this->Sanitize($_POST['lastname']);
$formvars['zipcode'] = $this->Sanitize($_POST['zipcode']);
$formvars['country'] = $this->Sanitize($_POST['country']);
$formvars['phonenumber'] = $this->Sanitize($_POST['phonenumber']);
$formvars['address'] = $this->Sanitize($_POST['address']);
$formvars['city'] = $this->Sanitize($_POST['city']);
$formvars['state'] = $this->Sanitize($_POST['state']);
}
function InsertIntoDB(&$formvars)
{
$confirmcode = $this->MakeConfirmationMd5($formvars['email']);
$formvars['confirmcode'] = $confirmcode;
$insert_query = 'insert into '.$this->tablename.'(
name,
email,
username,
password,
zipcode,
country,
phonenumber,
address,
city,
state,
confirmcode
)
values
(
"' . $this->SanitizeForSQL($formvars['name']) . '",
"' . $this->SanitizeForSQL($formvars['email']) . '",
"' . $this->SanitizeForSQL($formvars['username']) . '",
"' . md5($formvars['password']) . '",
"' . $this->SanitizeForSQL($formvars['zipcode']) . '",
"' . $this->SanitizeForSQL($formvars['country']) . '",
"' . $this->SanitizeForSQL($formvars['phonenumber']) . '",
"' . $this->SanitizeForSQL($formvars['address']) . '",
"' . $this->SanitizeForSQL($formvars['city']) . '",
"' . $this->SanitizeForSQL($formvars['state']) . '",
"' . $confirmcode . '"
)';
if(!mysql_query( $insert_query ,$this->connection))
{
$this->HandleDBError("Error inserting data to the table\nquery:$insert_query");
return false;
}
return true;
}