插入单选按钮的值

时间:2013-02-08 21:52:01

标签: php html mysql radio-button

我正在尝试在检入mysql db表时插入单选按钮的值。以下是用于执行此操作的HTML和PHP。请告诉我出了什么问题?

  

首先是HTML:

<div class='container'>
    <label for='username' >Business*:</label><br/>
    <input type="radio" name="bus" id="username" value="bus" maxlength="50" /><br/>
    <span id='register_username_errorloc' class='error'></span>
</div>
<div class='container'>
    <label for='username' >Personal*:</label><br/>
    <input type="radio" name="pers" id="username" value="per" maxlength="50" /><br/>
    <span id='register_username_errorloc' class='error'></span>
</div>
  

现在PHP:

function InsertIntoDB(&$formvars)
    {

        $confirmcode = $this->MakeConfirmationMd5($formvars['email']);

        $formvars['confirmcode'] = $confirmcode;

        $insert_query = 'insert into '.$this->tablename.'(
                name,
                email,
                username,
                password,
                confirmcode,
                dob,
                business,
                personal
                )
                values
                (
                "' . $this->SanitizeForSQL($formvars['name']) . '",
                "' . $this->SanitizeForSQL($formvars['email']) . '",
                "' . $this->SanitizeForSQL($formvars['username']) . '",
                "' . md5($formvars['password']) . '",
                "' . $confirmcode . '",
                "' . $this->SanitizeForSQL($formvars['dob']) . '",
                "' . $this->SanitizeForSQL($formvars['bus']) . '",
                "' . $this->SanitizeForSQL($formvars['pers']) . '"
                )';      
        if(!mysql_query( $insert_query ,$this->connection))
        {
            $this->HandleDBError("Error inserting data to the table\nquery:$insert_query");
            return false;
        }        
        return true;
    }

1 个答案:

答案 0 :(得分:1)

我认为存在逻辑错误。您只应将其中一个变量保存在数据库中的单选按钮中。

            "' . $this->SanitizeForSQL($formvars['bus']) . '",
           "' . $this->SanitizeForSQL($formvars['pers']) . '"
相关问题