注册表 - 为表创建新条目

时间:2013-05-01 15:05:23

标签: php sql database forms

我试图创建一个从注册表单中收集数据的表,并希望添加几行(zip,state等)。代码工作正常(名称,电子邮件,用户名等)除了行我补充道。任何想法为什么其他人得到好转,最新的条目没有被移动,他们似乎只是消失了。

更新:美国东部时间5-2-13 11:07 AM 提交表单时出错

 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!

CODE:

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;
}

1 个答案:

答案 0 :(得分:0)

计算数据库列;)在查询中(在更新中发布的输出中)有12列,但在VALUES语句中只有11列(可能缺少姓氏)。编辑您的PHP代码(添加lastname值),查询应该没有问题。