Jump to content

Recommended Posts

I'm building an application for people to book guest suites in a hotel.

This is the script i'm using

[code]

    if ($action == "input_details")
    {

        $query = mysql_query("SELECT suites,suitenos,maxnights,nightprice,deposit FROM gssettings WHERE id=1");
        $data = mysql_fetch_array($query);
        $maxnights = $data["maxnights"];
        $suites = $data["suites"];
        $suitenos = $data["suitenos"];
        $nightprice = $data["nightprice"];
        $deposit = $data["deposit"];
        $suite_numbers = split(",",$suitenos);
        $query = mysql_query("SELECT suiteno FROM gsdays WHERE date='$arrival'");
        $check = mysql_num_rows($query);

        if($check>=$suites)
        {
            $validate = 1;
            $error = "There are no suites available on $arrival";
        }

        while($data = mysql_fetch_array($query))
        {
            if ($a==1) break;
            for($i=0;$i<$suites;$i++)
            {
                $suiteno = $data["suiteno"];
                if ($a==1) break;
                if ($check==0)
                {
                    $use_suite = $suite_numbers[0];
                } else {
                    if ($suiteno != $suite_numbers[$i])
                    {
                        $use_suite = $suite_numbers[$i];
                        $a = 1;
                    } else {
                        $validate = 1;
                        $error .= "There are no suites available on $arrival";
                    }    
                }
            }
        }


        $departure = "$yearcheck-$monthcheck-$daycheck";
        $query = mysql_query("SELECT DATEDIFF('$departure','$arrival') AS datediff");
        $data = mysql_fetch_array($query);
        $datedifference = $data["datediff"];
        if ($datedifference > $maxnights)
        {
            $validate = 1;
            $error .= "<li>You are only able to reserve the guest suite for $maxnights days";
        }

        for($i=0;$i<$datedifference;$i++)
        {
            list($year,$month,$day) = split("-",$arrival);
            $this_date = date("Y-m-d",mktime(0,0,0,$month,$day+$i,$year));
            $query = mysql_query("SELECT * FROM gsdays WHERE date='$this_date'");
            $check = mysql_num_rows($query);
            if ($check >= $suites)
            {
                $validate = 1;
                $error .= "<li>There are no guest suites available on $this_date";
            }
        }

        if ($validate == 1)
        {
            echo $error;
            echo("<p><a href=\"guestsuite.php\" class=\"menu\">Click here to try again</a>");
        } else {

            $invoice = (($datedifference*$nightprice) + $deposit);
            $invoice_show = number_format((($datedifference*$nightprice) + $deposit),2);
            mysql_query("INSERT INTO gsdata (username,approved,suiteno,arrival,departure,invoice) VALUES ('$username',0,'$use_suite','$arrival','$departure','$invoice')");

            for($i=0;$i<$datedifference;$i++)
            {
                list($year,$month,$day) = split("-",$arrival);
                $this_date = date("Y-m-d",mktime(0,0,0,$month,$day+$i,$year));
                $query = mysql_query("SELECT id FROM gsdata ORDER BY id DESC LIMIT 1");
                $data = mysql_fetch_array($query);
                $dataid = $data["id"];
                mysql_query("INSERT INTO gsdays (suiteno,date,user,dataid) VALUES ('$use_suite','$this_date','$username','$dataid')");
            }

            echo<<<endhtml
                <b><center>Thank you for making your reservation</b><p>
                Your invoice total is $$invoice_show</center>
endhtml;
        }
    }
}

[/code]
The problem is $use_suite returns blank if there are no reservations, if there is one reservation it will use $suite_numbers[0]. Anyone see the problem?
Link to comment
https://forums.phpfreaks.com/topic/4845-complicated-logic/
Share on other sites

Perhaps if you described the data (tables and columns) and told us what you were trying to achieve it would save us a couple of hours trying to reverse-engineer a script that isn't even working and therefore only tells us what you don't want to do.
Link to comment
https://forums.phpfreaks.com/topic/4845-complicated-logic/#findComment-17141
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.