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

标签 php html css

我有两个表 rooinventory 和 reservation 我想在那个表中存储值但是它只能插入到 rooinventory 表中..

演示.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>

订单.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");
                }

            ?>

最佳答案

会不会是您的一个变量中的数据导致第二个查询失败?由于它们未作为参数绑定(bind)或至少已转义,因此它们可能会改变您的实际查询。例如,如果您的任何数据中有撇号,就会中断查询。

关于php - 我想将值存储在两个表中,但我可以存储在单个表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55444693/

相关文章:

php - Woocommerce 中特定支付网关结账时的附加字段

javascript - 如何通过添加子项使 div 溢出时可滚动

html - CSS - Bootstrap 选择下拉样式颜色

jquery - 使用 jQuery 提取单击的 HTML 表格的单元格索引

css - Susy 在 css 中添加奇怪的字符

html - 无法对齐联系人表格

php - Codeigniter 中的数据库加载问题

php - Docker Compose - 部署中的符号链接(symbolic link)

css - CSS 中重叠 div 的问题

javascript - 我的 ajax 调用数据部分中的 php 文件有什么问题?