将多个选中的复选框保存为数据库

时间:2017-02-12 13:36:00

标签: php html mysql database checkbox

帮助。如果选中的值超过1,如何将检查的值存储到数据库中并用逗号连接它。请帮助!非常感谢。代码如下: 救命。如果选中的值超过1,如何将检查的值存储到数据库中并用逗号连接它。请帮助!非常感谢。代码如下:

booknow.php

        <html>
        <form method="post" action="messageexec.php">
            <label for="currentDate"  style="color: #595959;">Date & Time: </label>
            <input type="text" title="Current date & time" style="background-color: #FAFAFA; color: grey;" name="currentDate" id="currentDate" readonly value="<?php  date_default_timezone_set("Asia/Manila"); echo date('M d, Y (g:i a)');?>"/>

            <label for="name">Name:</label>
            <input required type="text" name="name" id="name" title="Type your complete name" />

            <label for="address">Address:</label>
            <input required type="text" name="address" id="address" title="Type your complete address"/>

            <label for="email">Email:</label>
            <input required type="email" name="email" id="email" title="Type your email address"/>


            <label for="number">Contact No.</label>
            <input required type="text" name="number" id="number" maxlength="12" title="12 characters minimum" />   

</div>

    <div style="padding: 0px 50px; font-family: Helvetica, sans-serif; font-size: 1.4em;">
    Service:<br></div>
    <div style="padding: 0px 110px; float:left;  line-height: 140%; font-family: Helvetica, sans-serif; font-size: 1.4em;">
    <input type="checkbox" name="formDoor[]" value="Photography Service" /> Photography Service<br />
    <input type="checkbox" name="formDoor[]" value="Videography Service" /> Videography Service<br />
    <input type="checkbox" name="formDoor[]" value="Album Production" /> Album Production<br />
    <input type="checkbox" name="formDoor[]" value="Photo Printing Service" /> Photo Printing Service<br />
    <input type="checkbox" name="formDoor[]" value="Frame Production" /> Frame Production<br />
    <input type="checkbox" name="formDoor[]" value="Pictorial Service (Indoor and Outdoor)" /> Pictorial Service (Indoor and Outdoor)<br />
    <input type="checkbox" name="formDoor[]" value="Photography Studio Rental" /> Photography Studio Rental<br />
    <input type="checkbox" name="formDoor[]" value="Save the Date Production" /> Save the Date Production<br />
    <input type="checkbox" name="formDoor[]" value="Audio-Visual Production" /> Audio-Visual Production<br />
    <input type="checkbox" name="formDoor[]" value="Same Day Edit (On-site Video) Production" /> Same Day Edit (On-site Video) Production<br />
    <input type="checkbox" name="formDoor[]" value="Photobooth Service" /> Photobooth Service<br />
    <input type="checkbox" name="formDoor[]" value="Aerial Videography (using drones/quadcopters)" /> Aerial Videography (using drones/quadcopters)<br />
    </div>

                <br><br><br><br><br><br><br><br>
                <br><br><br><br><br><br><br>

<div id="contact-area">

            <label for="shootdate">Desired Date:</label>
            <input required type="date" name="shootdate" id="shootdate" title="Choose your desired date"/>

            <label for="shoottime">Desired Time:</label>
            <input required type="time" name="shoottime" id="shoottime" title="Choose your desired time"/>              

            <label for="place">Place of Event:</label>
            <input required type="text" name="place" id="place" title="Type the place of event"/>

            <label for="message">Additional Details:</label><br />
            <textarea placeholder="Optional" type="text" name="message" rows="20" cols="20" id="message" title="Additional details"></textarea>

            <?php include "popup.php"; ?>               
            <input type="submit" name="submit" value="Book Now" class="submit-button" />
        </form>
        <html>

messageexec.php

    <?php
    $currentDate = $_POST['currentDate'];
    $name = $_POST['name'];
    $address = $_POST['address'];   
    $email = $_POST['email'];   
    $number = $_POST['number']; 
    $services = $aDoor;
    $shootdate = $_POST['shootdate'];
    $shoottime = $_POST['shoottime'];
    $place = $_POST['place'];
    $message = $_POST['message'];
    mysqli_query($GLOBALS["___mysqli_ston"], "INSERT INTO message (currentDate, name, address, email, number, services, shootdate, shoottime, place, message) VALUES ('$currentDate','$name','$address','$email', '$number','$services', '$shootdate', '$shoottime', '$place', '$message')");
    echo "<script>alert('Thank you! Your reservation will be under review. Studio1 will email you once reviewed.'); window.location = './booknow.php';</script>";
      ?>

1 个答案:

答案 0 :(得分:0)

直接存储连接值是合理的:

$formDoor = isset ($_POST ['formDoor']) ? $_POST ['formDoor'] : array ();
$concatenate = implode (",", $formDoor);

然后,您可以在数据库查询中使用$concatenate变量。