2017-10-12 35 views
-1

基本上我有一個表單,我可以選擇人體頭像。阿凡達1有金色的頭髮和藍色的眼睛,阿凡達2有棕色的頭髮和棕色的眼睛。

我的頭像

<input type="radio" name="avatarblondeblue" value="blondeblue"> 
<input type="radio" name="avatarbrownbrown" value="brownbrown"> 

在我的MySQL表這種輸入形式,我稱之爲叫「hair_color」和一列一列「eye_color」。

是否有可能只使用一個輸入提交,例如,「金髮」列的hair_color和「藍色」列eye_color?

編輯:的解決辦法是設置的名稱相同,並創建一個if-then語句是這樣的:

if ($_POST['avatar'] == 'blondeblue') { 
    $hair_color = mysqli_real_escape_string ($con, 'blonde'); 
    $eye_color = mysqli_real_escape_string ($con, 'blue'); 

回答

1

這是你的問題來選擇化身的解決方案。你必須對輸入的收音機同名,並將你的數據放在value屬性中。

<!DOCTYPE html> 
<html> 
<body> 
<?php 
if(isset($_POST['submit'])) 
{ 
    $data=explode("b",$_POST['avatar']); 
    echo "hair_color - b".$data[0]; 
    echo "<br>"; 
    echo "eye_color - b".$data[1]; 
} 
?> 
<form method="post" action=""> 
<input type="radio" name="avatar" value="blondeblue"> Avatar Blonde Blue 
<br/> 
<input type="radio" name="avatar" value="brownbrown"> Avatar Brown Brown 
<br/> 
<input type="submit" name="submit" /> 
</form> 
</body> 
</html> 
相關問題