我想获得用户选择的选项和&#34;值&#34;将<option>
存储在他的帐户中(我有一个MySQL注册系统)。
我做了桌子,一切都很好,用户名工作得很好,密码工作得很好,但是我被困在选择部分:
<td>team:</td>
<td>
<select name="teamlist" form="regform">
<option value="AstraGiu">Astra Giurgiu</option>
<option value="FCBotosani">FC Botosani</option>
<option value="FCBrasov">FC Brasov</option>
<option value="CeahlaulPN">Ceahlaul Piatra Neamt</option>
<option value="CFRCluj">CFR Cluj</option>
<option value="DinamoBuc">Dinamo Bucuresti</option>
<option value="FarulCta">Farul Constanta</option>
<option value="GazMetanM">Gaz Metan Medias</option>
<option value="OtelulGal">Otelul Galati</option>
<option value="PanduriiTgJiu">Pandurii Targu-Jiu</option>
<option value="PetrolulPlo">Petrolul Ploiesti</option>
<option value="RapidBuc">Rapid Bucuresti</option>
<option value="SteauaBuc">Steaua Bucuresti</option>
<option value="UCluj">Universitatea Cluj</option>
<option value="UCraiova">Universitatea Craiova</option>
<option value="UTAArad">UTA Arad</option>
<option value="FCVaslui">FC Vaslui</option>
</select>
</td>
用户输入用户名,传递并选择团队后,我已经创建了这个按钮......
<td colspan="2" align="right"><input type="submit" name="submit" value="register"/></td>
如果这对您有帮助,请按照以下方式存储..
<?php
if (isset($_POST['submit'])) {
$username = secure('username');
$password = md5($_POST['password']);
$team = secure('team');
if (empty($_POST['username'])) {
echo "The username field is empty.";
} else {
if (empty($_POST['password'])) {
echo "The password field is empty.";
} else {
if (empty($_POST['team'])) {
echo "The team field is empty.";
} else {
$query = mysql_query("SELECT * FROM `users` WHERE `username` = '". $username ."'") or die(mysql_error());
if(mysql_num_rows($query) == 1){
echo "The username already exists.";
} else {
$query = mysql_query("INSERT INTO `users` VALUES(NULL, '". $username ."', '". $password ."', '". team ."')") or die(mysql_error());
echo "Successfully registered.";
}
}
}
}
}
?>
如何获得他选择的团队并存储&#34;值&#34;在MySQL数据库中的那个团队(选项)?
答案 0 :(得分:1)
你试过这个吗?
$_POST['teamlist']
我假设您的secure
函数接受表单元素的名称,因此您可以更改此行:
$team = secure('teamlist');
并改变这一点:
if (empty($_POST['teamlist'])) {
echo "The team field is empty.";
}
虽然我在验证中看到您订阅了arrow anti-pattern