我想尝试将复选框和单选按钮的值插入我的数据库...当我选择复选框选项并选择单选按钮选项时,复选框和单选按钮的值将记录在数据库的同一行中。 ..我有 3 个菜单选择..每个菜单都有 2 个大小选项,即单选按钮..这意味着每个大小选项应该有不同的名称,对吗??...我的意思是 field1[]....
这是我的代码
恢复.php
Menu :
<input type="checkbox" value="Siomay" name="tile[]">Siomay <br>
<input type="radio" name="field1[]" value="4" />Small
<input type="radio" name="field1[]" value="5" />Large<br>
<input type="checkbox" value="Batagor" name="tile[]">Batagor <br>
<input type="radio" name="field2[]" value="4" />Small
<input type="radio" name="field2[]" value="5" />Large<br>
<input type="checkbox" value="Pempek" name="tile[]">Pempek<br>
<input type="radio" name="field3[]" value="4" />Small
<input type="radio" name="field3[]" value="5" />Large<br>
<input name="confirm" type=submit id="confirm" value='Confirm'>
</form>
菜单2.php
<?php
$con = mysql_connect("localhost","root");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("project1", $con);
$Tile = mysql_real_escape_string($_POST['tile']);
$Field = mysql_real_escape_string($_POST['field1']);
if ( !empty($Tile) && !empty($Field) ) {
$insert="INSERT INTO menu(name, price) VALUES ('$Tile','$Field')";
if (!mysql_query($insert, $con)) {
die('Error: ' . mysql_error());
}
echo "1 record added";
}
else echo "Please select at least 1 menu.";
mysql_close($con)
?>