将单选按钮和复选框的值放入数据库

时间:2012-07-17 12:33:48

标签: php database checkbox radio-button

  

可能重复:
  put the value of radio button and check box into database PHP

我在menu2.php上收到错误消息“Undefined Index”,这是

$Field = mysql_real_escape_string($_POST['field3']);

resto.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>

menu2.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']);
$Field = mysql_real_escape_string($_POST['field2']);
$Field = mysql_real_escape_string($_POST['field3']);

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) 
?>

0 个答案:

没有答案