我在创建表单时遇到很多问题......
<form method="post" action="target.php" id="myForm">
<span class="form_col">Name</span>
<input />
<br /><br />
<span class="form_col">Gender :</span>
<label><input name="sex" type="radio" value="H" />Male</label>
<label><input name="sex" type="radio" value="F" />Female</label>
<br /><br />
<label class="form_col">Race :</label>
<label><input type="radio" value="Human" />Human</label>
<label><input type="radio" value="Elf" />Elf</label>
<label><input type="radio" value="Orc" />Orc</label>
<br /><br />
<label class="form_col">Primary color :</label>
<select name="prcolor" id="prcolor">
<option value="none">Select the primary color</option>
<option value="blue">Blue</option>
<option value="red">Red</option>
<option value="yellow">Yellow</option>
<option value="black">Black</option>
</select>
<br /><br />
<label class="form_col" for="firstName">Body color :</label>
<select name="bcolor" id="bcolor">
<option value="base">Base</option>
<option value="redb">Red</option>
<option value="brownb">Brown</option>
<option value="blackb">Black</option>
</select>
<br /><br />
<label class="form_col">Hair color :</label>
<select name="hair" id="hair">
<option value="none">Select the color</option>
<option value="blackh">Black</option>
<option value="greyh">Grey</option>
<option value="brownh">Brown</option>
</select>
<br /><br />
<span class="form_col">Weapon :</span>
<label><input type="radio" value="sword" />Sword</label>
<label><input type="radio" value="shield" />Shield</label>
<label><input type="radio" value="knife" />Knife</label>
<label><input type="radio" value="wand" />Wand</label>
<br /><br />
<span class="form_col">Clothes :</span>
<label><input type="checkbox" value="armor" />Armor</label>
<label><input type="checkbox" value="coat" />coat</label>
<label><input type="checkbox" value="dress" />Dress</label>
<br /><br />
<span class="form_col">Accessory :</span>
<label><input type="checkbox" value="hat" />Hat</label>
<label><input type="checkbox" value="helmet" />Helmet</label>
<label><input type="checkbox" value="glasses" />Glasses</label>
<br /><br />
<span class="form_col">Pet :</span>
<label><input name="sex" type="radio" value="mount" />Mount</label>
<label><input name="sex" type="radio" value="pet" />Pet</label>
<label><input name="sex" type="radio" value="none" />None</label>
<br /><br />
<span class="form_col"></span>
<input type="submit" value="Send" />
</form>
我需要将这些信息发送到数据库,但我不知道该怎么做...... 在mysql上我不知道我需要为每个信息使用哪种类型......
任何人都可以帮我制作这个表格吗? 其实我真的不知道怎么做,我做了一些研究,但没有结果......
提前致谢
答案 0 :(得分:-1)
你是php表格页面。
<form method="post" action="target.php" id="myForm">
<span class="form_col">Name</span>
<input />
<br /><br />
<span class="form_col">Gender :</span>
<label><input name="sex" type="radio" value="H" />Male</label>
<label><input name="sex" type="radio" value="F" />Female</label>
<br /><br />
<label class="form_col">Race :</label>
<label><input name="race" type="radio" value="Human" />Human</label>
<label><input name="race" type="radio" value="Elf" />Elf</label>
<label><input name="sex" type="radio" value="Orc" />Orc</label>
<br /><br />
<label class="form_col">Primary color :</label>
<select name="prcolor" id="prcolor">
<option value="none">Select the primary color</option>
<option value="blue">Blue</option>
<option value="red">Red</option>
<option value="yellow">Yellow</option>
<option value="black">Black</option>
</select>
<br /><br />
<label class="form_col" for="firstName">Body color :</label>
<select name="bcolor" id="bcolor">
<option value="base">Base</option>
<option value="redb">Red</option>
<option value="brownb">Brown</option>
<option value="blackb">Black</option>
</select>
<br /><br />
<label class="form_col">Hair color :</label>
<select name="hair" id="hair">
<option value="none">Select the color</option>
<option value="blackh">Black</option>
<option value="greyh">Grey</option>
<option value="brownh">Brown</option>
</select>
<br /><br />
<span class="form_col">Weapon :</span>
<label><input name="weapon" type="radio" value="sword" />Sword</label>
<label><input name="weapon" type="radio" value="shield" />Shield</label>
<label><input name="weapon" type="radio" value="knife" />Knife</label>
<label><input name="weapon" type="radio" value="wand" />Wand</label>
<br /><br />
<span class="form_col">Clothes :</span>
<label><input name="clothes" type="checkbox" value="armor" />Armor</label>
<label><input name="clothes" type="checkbox" value="coat" />coat</label>
<label><input name="clothes" type="checkbox" value="dress" />Dress</label>
<br /><br />
<span class="form_col">Accessory :</span>
<label><input name="Acc" type="checkbox" value="hat" />Hat</label>
<label><input name="Acc" type="checkbox" value="helmet" />Helmet</label>
<label><input name="Acc" type="checkbox" value="glasses" />Glasses</label>
<br /><br />
<span class="form_col">Pet :</span>
<label><input name="pet" type="radio" value="mount" />Mount</label>
<label><input name="pet" type="radio" value="pet" />Pet</label>
<label><input name="pet" type="radio" value="none" />None</label>
<br /><br />
<span class="form_col"></span>
<input type="submit" value="Send" name="submit"/>
</form>
你的target.php
<?php
if(isset($_POST['submit']))
{
$con = mysqli_connect('servername','username','password','databasename');
$v_sex = $_POST['sex'];
$v_race = $_POST['race'];
$v_prcolor = $_POST['prcolor'];
$v_bcolor = $_POST['bcolor'];
$v_hair = $_POST['hair'];
$v_weapon = $_POST['weapon'];
$v_clothes = $_POST['clothes'];
$v_Acc = $_POST['Acc'];
$_pet = $_POST['pet'];
$result = mysqli_query($con,"insert into table_name(sex,race,prcolor,bcolor,hair,weapon,clothes,Acc,pet) values ('$v_sex','$v_race','$v_prcolor','$v_bcolor','$v_hair','$v_weapon','$v_clothes','$v_Acc','$v_pet');
echo "Data saved successfully!";
}
?>
您的表格如下:
Table Name : Table1
Fields Name :
sex varchar(10),
race varchar(20),
prcolor varchar(20),
bcolor varchar(20),
hair varchar(20),
weapon varchar(20),
clothes varchar(20),
Acc varchar(20),
pet varchar(20)