0

i have two table rooinventory and reservation i want to store values in that tables but its getting inserting in rooinventory table only..

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

            ?>
jeroen
  • 91,079
  • 21
  • 114
  • 132
  • 1
    A few important details on this piece of code, first please use `mysqli_query`instead of `mysql_query`. You are working with deprecated code atm. Also please read the PHP manual on inserting variables in a SQL query. You must use `mysqli_real_escape_string` (https://www.php.net/mysqli-real-escape-string) – n9iels Mar 31 '19 at 20:17
  • As answer on your question: start with adding a `mysqli_error` (https://www.php.net/manual/en/mysqli.error.php) to catch any errors when executing the query. This will tell why the query fails. – n9iels Mar 31 '19 at 20:19
  • 1
    @n9iels [Use prepared statements](https://stackoverflow.com/a/60496/9029328), and you don't have to keep track of what might or might not have been escaped. – AuxTaco Apr 01 '19 at 02:04

1 Answers1

0

Could it be the data in one of your variables is causing the second query to fail? Since they're not bound as parameters or at least escaped, they could be altering your actual query. For instance, if there's an apostrophe in any of your data, it's going to break the query.

Lucas Krupinski
  • 682
  • 5
  • 16