确定!所以我不是PHP的专家。我无法将我的单选按钮数据插入"性别"数据库中的列。
Register.php
<label for='gender' >Gender*: </label><br/>
<input type="radio" name="genderf" id="genderf" value='<?php echo $fgmembersite->SafeDisplay('gender') ?>'maxlength="50"/> Female
<input type="radio" name="genderm" id="genderm" value='<?php echo $fgmembersite->SafeDisplay('gender') ?>'maxlength="50"/>Male
和 fgmembersite.php 就是这个我只是插入功能代码,它会将数据从register.php收集到数据库
function CollectRegistrationSubmission(&$formvars)
{
$formvars['name'] = $this->Sanitize($_POST['name']);
$formvars['gname'] = $this->Sanitize($_POST['gname']);
$formvars['age'] = $this->Sanitize($_POST['age']);
$formvars['gender'] = $this->Sanitize($_POST['genderm']);
$formvars['gender'] = $this->Sanitize($_POST['genderf']);
$formvars['school_college'] = $this->Sanitize($_POST['school_college']);
$formvars['class_section'] = $this->Sanitize($_POST['class_section']);
$formvars['stream'] = $this->Sanitize($_POST['stream']);
$formvars['phone_number'] = $this->Sanitize($_POST['phone_number']);
$formvars['username'] = $this->Sanitize($_POST['username']);
$formvars['email'] = $this->Sanitize($_POST['email']);
$formvars['password'] = $this->Sanitize($_POST['password']);
}
$insert_query = 'insert into '.$this->tablename.'(
name,
gname,
age,
gender,
school_college,
class_section,
stream,
phone_number,
email,
username,
password,
salt,
confirmcode
)
values
(
"' . $this->SanitizeForSQL($formvars['name']) . '",
"' . $this->SanitizeForSQL($formvars['gname']) . '",
"' . $this->SanitizeForSQL($formvars['age']) . '",
"' . $this->SanitizeForSQL($formvars['gender']) . '",
"' . $this->SanitizeForSQL($formvars['school_college']) . '",
"' . $this->SanitizeForSQL($formvars['class_section']) . '",
"' . $this->SanitizeForSQL($formvars['stream']) . '",
"' . $this->SanitizeForSQL($formvars['phone_number']) . '",
"' . $this->SanitizeForSQL($formvars['email']) . '",
"' . $this->SanitizeForSQL($formvars['username']) . '",
"' . $encrypted_password . '",
"' . $salt . '",
"' . $confirmcode . '"
)';
There are no errors or exceptions , just the gender column is empty in spite of checking the radio button.
答案 0 :(得分:0)
对于无线电输入,name
应该相同,因为您只能选择一个。在您的情况下gender
<input type="radio" name="gender" id="genderf" value='<?php echo $fgmembersite->SafeDisplay('gender') ?>'maxlength="50"/> Female
<input type="radio" name="gender" id="genderm" value='<?php echo $fgmembersite->SafeDisplay('gender') ?>'maxlength="50"/>Male
我不知道$fgmembersite->SafeDisplay('gender')
呈现的是什么,但你看起来只有 m 和 f
然后你使用$_POST['gender']
$formvars['gender'] = $this->Sanitize($_POST['gender']);
我想补充一下,有两个以上的性别。
答案 1 :(得分:0)
$formvars['gender'] = $this->Sanitize($_POST['genderm']);
$formvars['gender'] = $this->Sanitize($_POST['genderf']);
^^^^^^
通过f
单选按钮发送的任何内容都将覆盖m
单选按钮,因为您的数组键是相同的。