I would like to include the number of reservations in the session in the inventory management for accommodation reservations.

Asked 3 months ago, Updated 3 months ago, 15 views

With the calendar reservation system, I want to incorporate the number of reservations in the session into inventory management, but it doesn't work.
Please advise me if there is a good way.

】Where it's made br
By referring to the item number from the database, the number of reservations made on the day the reservation data is reserved is referred to the number $max in stock to determine whether there is any stock available or not

US>Data to check inventory
$reservday date and time
Total $max inventory *$max<$m out of stock

1. Take out the reservation data and count the number of reservations

$m=0;
mysql_select_db($DBNAME,$connect);
mysql_query("SET NAMES utf8");
$query="SELECT* FROM save_table WHERE type='$room_id'AND save_day='$reservday'";
$result=mysql_query($query) or die(mysql_error());
    while($row=mysql_fetch_array($result)){
        $m++;
    }

2. Contents of Session $_SESSION[item]

Array( 
// [key] 1 item x unique KEY [reserve_day] reservation start date [renpaku] number of consecutive nights
[0] =>Array([key]=>1458583223[type]=>5[reserve_day]=>20160322[renpaku]=>1) 
[1] =>Array([key]=>1458583836[type]=>5[reserve_day]=>20160327[renpaku]=>1) 
[2] =>Array([key]=>1458584148[type]=>1[reserve_day]=>20160321[renpaku]=>1) 
)

[What I want to do]
I want to add $m in session variable to the number of reservations to $m in 1.
The writing below did not work properly.I would appreciate it if you could advise me on how to correct this.

3. Add the number of session reservations to the number of database reservations

foreach($_SESSION['item'] as $od=>$val){
$type=$val[room_id];
$reserve_day = $val [reserve_Day];
$renpaku=$val[renpaku]; // Days of consecutive nights
$ren = 0;

if($type==$row[type]){

  // Separate reserve_day for daily reservation, support monthly reservation
  $year=substr($reserve_day,0,4);
  $mon=substr($reserve_day,4,2);
  $day = substr($reserve_day, 6, 2);

  // Make sure all days of the daily reservation are added to the number of reservations
  for($i=1;$i<=$renpaku;$i++){
    if($renpaku>=2){
      $tomorrow=mktime(0,0,0,$mon,$day+$ren,$year);
      $reserve_day=date(Ymd, $tomorrow);
    }
    $ren++;
  }
  $m++;//Isn't this the right place?
}

php session

2022-09-30 11:32

1 Answers

There are many obvious mistakes and bad points, so I think it's better to start with the basics.

  • mysql_* family functions are too old and deprecated
  • SET NAMES utf-8 must not specify character encoding
  • If the variables are embedded directly in SQL and have not been pre-escaped, SQL injection is possible.Let's use placeholder.(Not recommended) If you want to escape, the theory is to do it simultaneously with the assembly to prevent leakage.
  • As the comment pointed out, if you need the number of lines, use the COUNT instead of looping the results you get.
  • The associative array key is not bound by ' or " and is not string literal, is it okay?
  • You are trying to get a value keyed with room_id from the associative array, but it is not included in the data provided.(Error in type?)
  • Similarly reserve_Day.(reserve_day error?)
  • No need for loops handling "day-to-day reservations" as they only need to add the value of $renpaku

As for the reservation, if you don't handle the transaction properly, it's like double booking. (Reference: I've created a hotel reservation system that makes me doublebook when there's a stormy concert|Tokumaru Hiroshi's diary.

Web applications can easily create security holes if they are not careful.At least read IPA's How to create a secure website.It is recommended that you study with trusted books such as "How to Create a Secure Web Application to Learn Systematically" (ISBN 4797361190).

I don't know any recommendations for PHP's introduction book (because I haven't read it), but I was in charge of reviewing "The easiest PHP textbook"|Tokumaru Hiroshi's Diary" book review will be helpful


2022-09-30 11:32

If you have any answers or tips


© 2023 OneMinuteCode. All rights reserved.