0

嗨,我正在尝试为我工作的学校创建一个表格,以便工作人员可以在他们想要在学校礼堂设置投影仪时进行预订。到目前为止,我有日期、时间、名称的文本框字段,但我还想要一个复选框字段,以便他们可以选择是否要借用笔记本电脑并发出声音。

我的问题是我找不到如何将复选框中的值放入数据库中。提前感谢您的帮助。

这是我到目前为止...

HTML

<form action="mysql-insert.php" method="post">

<p>Date: <input name="date" type="text" id="datepicker" /></p>

<p>Time : <input name="time" type="text" /></p>

<p>Name : <input name="name" type="text" /></p>

<p>Laptop <input name="chkbox[]" type="checkbox" value="Laptop" /></p>

<p>Sound <input name="chkbox[]" type="checkbox" value="Sound" /></p>



<p><input name="submit" type="submit" value="Save Hall Setup Request" /></p>

</form>

PHP

<?php
$dbserver = 'localhost';
$dbuser = 'root';
$dbpassword = '';
$dbdatabase = 'hall_setup';

$cn  = mysql_connect($dbserver , $dbuser, $dbpassword);

if (!mysql_select_db($dbdatabase, $cn)) {
    echo "Sorry, could not connect to $dbdatabase";
    die();
}


if (!isset($_POST['submit'])) {
    header("Location: mysql-insert-form.php");
    die();
}

$date = $_POST['date'];
$time = $_POST['time'];
$name = htmlspecialchars(trim($_POST['name'])); 
$laptop = $_POST['chkbox'];

$name = mysql_real_escape_string($name);

$sql = "INSERT INTO laptoprequest 
        (date, time, name, laptop) 
        VALUES 
('$date', '$time', '$name', '$laptop')"; 

if(!mysql_query($sql, $cn)) {

    print "Error - data not submitted";
    die();
};

header("Location: hall_setup.php");


?>
4

1 回答 1

0
<?php   

<input type="checkbox" name="check_list[]" value="English" required>
<label>English</label>
<input type="checkbox" name="check_list[]" value="Non English" required>
<label>Non English</label>
<input id="button" type="submit" name="submit" value="Submit">
?>

//above question for answer this..>>>
<?php
$checkbox = $_POST['check_list'];
    if($_POST["submit"]=="submit"){
        for($i=0;$i<sizeof($checkbox);$i++){
            $query1="INSERT INTO user(language) VALUES 
('".$checkbox[$i]."')";
            mysql_query($query1) or die(mysql_error());
        }
        echo "Record is inserted.."
    }
?>
于 2017-08-29T20:50:44.133 回答