sfsfx

Insert into (Booking form)

Apr 16th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.76 KB | None | 0 0
  1. public function insert(Request $request)
  2.     {
  3.         $vehicle_user   = Auth::user()->ic_number;
  4.         $vehicle_status = 'Pending';
  5.         $vehicle_name   = $request->input('vehicle_name');
  6.         $event_name     = $request->input('event_name');
  7.         $event_dest     = $request->input('event_dest');
  8.         $book_time      = $request->input('book_time');
  9.         $return_time    = $request->input('return_time');
  10.        
  11.         $overlap = DB::select("SELECT count(*) countid FROM vehicle_table
  12.                    WHERE ('$book_time' < return_time)
  13.                    AND
  14.                    ('$return_time' > book_time)"
  15.                   );
  16.        
  17.         $array = json_decode(json_encode($overlap), true);
  18.         $count_data = $array[0]['countid'];
  19.        
  20.         if($count_data == 0)
  21.         {  
  22.             DB::insert('INSERT INTO vehicle_table (
  23.            vehicle_user,
  24.            vehicle_name,
  25.            event_name,
  26.            event_dest,
  27.            book_time,
  28.            return_time,
  29.            vehicle_status
  30.            ) VALUES(?, ?, ?, ?, ?, ?, ?)', [
  31.             $vehicle_user,
  32.             $vehicle_name,
  33.             $event_name,
  34.             $event_dest,
  35.             $book_time,
  36.             $return_time,
  37.             $vehicle_status,
  38.             ]);
  39.            
  40.             header("Location: /vehicle", true, 301);
  41.             exit();
  42.         }
  43.        
  44.         else
  45.         {
  46.             echo "<script> if (alert('Invalid date. Please choose another date!'))
  47.                            {
  48.                            }
  49.                            else
  50.                            {
  51.                                window.location.replace('/vehicle');
  52.                            } </script> ";
  53.         }
  54.     }
Advertisement
Add Comment
Please, Sign In to add comment