【问题标题】:Insert into value of Radio button插入单选按钮的值
【发布时间】:2013-01-24 18:28:54
【问题描述】:

当单选按钮签入 mysql 数据库表时,我试图插入它的值。下面是执行此操作的 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;
    }

【问题讨论】:

  • 这甚至与我所要求的相差无几。
  • 提交后,这两个单选值都没有出现在数据库中吗?
  • 正确的sbeliv01,无论是否检查,值都不会进入数据库。
  • 没关系,没有为无线电字段定义变量。很抱歉浪费了时间。感谢您的帮助

标签: php html mysql radio-button


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2017-04-27
    • 2014-10-07
    • 2017-04-11
    • 1970-01-01
    • 1970-01-01
    • 2015-08-12
    • 2012-10-14
    • 2022-01-10
    相关资源
    最近更新 更多