我想将值存储在两个表中,但我可以存储在单个表中

时间:2019-03-31 19:37:05

标签: php html css

我有两个表rooinventory和保留区,我想将值存储在该表中,但是它只能插入到rooinventory表中。.

demo.php

<form name="checkoutForm" method="post" action="order.php">
    <div class="container" style="float: left; width: 299px; margin-left: 12px;">
        <span class="top-label">
            <span class="label-txt">Room Details</span>
        </span>

        <div class="content-area" style="border-radius:15px;">
            <div>

            </div>
            <div class="content drop-here">
                <div id="cart-icon">
                    <img src="img/Shoppingcart_128x128.png" alt="shopping cart" class="pngfix" width="128" height="128" />
                    <img src="img/ajax_load_2.gif" alt="loading.." id="ajax-loader" width="16" height="16" />
                </div>


                <input name="start" type="hidden" value="<?php echo $arival; ?>" />
                <input name="end" type="hidden" value="<?php echo $departure; ?>" />
                <input name="numnights" type="hidden" value=<?php echo $numberofnights; ?>" />

                <div>
                    <div id="item-list">
                    </div>
                    <div id="total"></div>
                </div>
                <div class="clear"></div>
          </div>

        </div>


    </div>

        <span class="top-label">
            <span class="label-txt">Personal Details</span>
        </span>
        <div class="content-area" style="border-radius:15px; padding-bottom: 25px;">
            <div>
                Firstname:<br>
                <input type="text" name="fname" id="boxy" pattern="[A-Za-z]{1,32}" required="" /><br>
                lastname:<br>
                <input type="text" name="lname" id="boxy" required="" /><br>
                Address:<br>
                <input type="text" name="address" id="boxy" pattern="[A-Za-z]{1,32}" required="" /><br>
                City:<br>
                <input type="text" name="city" id="boxy" required="" /><br>
                Country:<br>
                <input type="text" name="country" id="boxy" required="" /><br>
                Email:<br>
                <input type="email" name="email" id="boxy" /><br>
                Contact Number:<br>
                <input type="text" name="contact" id="boxy" required="" /><br>
                <input type="hidden" name="confirmation" id="boxy" value="<?php echo $confirmation ?>" /><br>
                <input type="submit" name="check" onclick="document.forms.checkoutForm.submit(); return false;" class="button" value="Checkout" id="boxy"  style="width: 147px; margin-top: 18px;">
            </div>
        </div>
    </div>
    </form>

order.php

<?php
            $confirmation = $_POST['confirmation'];
            $numnights=round($_POST['numnights']);
            $arival=$_POST['start'];
            $departure=$_POST['end'];
            $firstname=$_POST['fname'];
            $lastname=$_POST['lname'];
            $address=$_POST['address'];
            $city=$_POST['city'];
            $country=$_POST['country'];
            $email=$_POST['email'];
            $contact=$_POST['contact'];
            $stat='active';
            $roomid=$_POST['id'];
            $qty=$_POST['qty'];
            $price=$_POST['price'];
            $roomname=$_POST['roomname'];
            $N = count($roomid);
            $ip_sqlq=mysql_query("select * from rooinventory where confirmation='$confirmation' and arrival='$arival'and departure='$departure'");
                $countq=mysql_num_rows($ip_sqlq);
                if($countq==0)
                {
                    for($i=0; $i < $N; $i++)
                    {

                    mysql_query("INSERT INTO rooinventory (room, qty, arrival, departure, status, confirmation) VALUES ('$roomid[$i]','$qty[$i]','$arival','$departure','$stat','$confirmation')");

                echo '<h2>'.$qty[$i].' x '.$roomname[$i].' = '.$ble=$qty[$i]*$price[$i].'</h2>';
                    echo '<div style="display:none;">';
                    $dddd=$ble;
                    $total=$total+$dddd;
                    echo '</div>';
                    }
                    mysql_query("INSERT INTO reservation (firstname, lastname, city, address, country, email, contact, arrival, departure, result, payable, status, confirmation) VALUES ('$firstname','$lastname','$city','$address','$country','$email','$contact','$arival','$departure','$numnights','$total','$stat','$confirmation')");
                    header("location: paypalpayout.php?confirm=$confirmation");
                }
                else{
                header("location: ../index.php");
                }

            ?>

1 个答案:

答案 0 :(得分:0)

可能是您的变量之一中的数据导致第二个查询失败吗?由于它们未绑定为参数或至少未进行转义,因此它们可能会更改您的实际查询。例如,如果您的任何数据中都有单引号,它将破坏查询。