php - 插入单选按钮的值

标签 php html mysql radio-button

我试图在检查到 mysql 数据库表时插入单选按钮的值。下面是这样做的 HTML 和 PHP。请让我知道出了什么问题?

Here is the HTML first:

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

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

最佳答案

我觉得有逻辑错误。您应该只在数据库中保存单选按钮中的变量之一。

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

关于php - 插入单选按钮的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14781907/

相关文章:

javascript - 我如何在 Codeigniter 中处理 pdf 格式的文件下载?

php - 使用 php if 语句进行过滤

php - 我的 csv 导出显示 html,如何摆脱?

php - 如何使用 jQuery 在 HTML 中添加换行符

javascript - 使用 javascript 删除 html

MySQL phpmyadmin 替代品(mySQL workbench like)

PHP 必填字段

css - iframe 水平滚动不在 iOS 上呈现

mysql - 基于条件的SQL查询

C# MySQL 对字段类型的错误解释