hey guys i need help my database is not receiving any data that has been entered to my form and there's no error so i paste the function that i used to the form and i attached the file booking.php

booking.php<?php
    session_start();
      // connect to database
$db = mysqli_connect('localhost', 'root', '12345', 'hotel booking');

// variable declaration
$username = "";
$Email    = "";
$Phonenumber = "";
$country = "";
$bookdate ="";
$meals ="";
$numberofguest ="";
$Room ="";
$Foodmenu ="";
$errors = array();

// call the register() function if register_btn is clicked
if (isset($_POST['register_btn'])) {
      register();
}

// REGISTER USER
function register(){
      // call these variables with the global keyword to make them available in function
      global $db, $errors, $username, $Email , $Phonenumber , $country, $bookdate, $meals, $numberofguest, $Room, $Foodmenu;

      // receive all input values from the form. Call the e() function
    // defined below to escape form values

      $username    = e($_POST['username']);
      $Email       = e($_POST['Email']);
      $Phonenumber = e($_POST['Phonenumber']);
      $country     = e($_POST['country']);
    $bookdate    = e($_POST['bookdate  ']);
      $meals       = e($_POST['meals']);
      $numberofguest = e($_POST['numberofguest']);
      $Room = e($_POST['Room']);
      $Foodmenu = e($_POST['Food menu']);
      // form validation: ensure that the form is correctly filled
      if (empty($username)) {
            array_push($errors, "username is required");
      }
      if (empty($Email)) {
            array_push($errors, "Email is required");
      }
      if (empty($Phonenumber)) {
            array_push($errors, "Phonenumber is required");
    }
      if (empty($country)) {
            array_push($errors, "country is required");
    }
      if (empty($bookdate)) {
            array_push($errors, "bookdate is required");
    }
      if (empty($meals)) {
            array_push($errors, "meals is required");
    }
      if (empty($numberofguest)) {
            array_push($errors, "numberofguest is required");
    }
      if (empty($Room)) {
            array_push($errors, "Room is required");
    }
      if (empty($Foodmenu)) {
            array_push($errors, "Foodmenu is required");
    }
      // register user if there are no errors in the form
      

            if (isset($_POST['personal details'])) {
                  $user_type = e($_POST['personal details']);
                  $query = "INSERT INTO `personal details` (`IDNUMBER`, `username`, `Email`, `Phonenumber`, `country`, `book date`, `meals`, `number of guest`, `Room`, `Food menu`)
                  VALUES (NULL, '$username', '$Email', '$Phonenumber', '$country', '$bookdate', '$meals', '$numberofguest', '$Room', '$Foodmenu') ";
                  mysqli_query($db, $query);
                  $_SESSION['success']  = "New user successfully created!!";
                  header('HOME PAGE 1.HTML');
            }else{
                  $query = "INSERT INTO `personal details` (`IDNUMBER`, `username`, `Email`, `Phonenumber`, `country`, `book date`, `meals`, `number of guest`, `Room`, `Food menu`)
                  VALUES (NULL, '$username', '$Email', '$Phonenumber', '$country', '$bookdate', '$meals', '$numberofguest', '$Room', '$Foodmenu') ";
                  mysqli_query($db, $query);

                  // get id of the created user
                  $logged_in_personaldetails_id= mysqli_insert_id($db);
                  $_SESSION['personaldetails'] = getUserById($username); // put logged in user in session
                  $_SESSION['success']  = "New user successfully created!!";
                  header('HOME PAGE 1.HTML');
            }
      }
// return user array from their id
function getUserById($username){
      global $db;
      $query = "SELECT * FROM `personal details` WHERE `username`  ='$username'";
      $result = mysqli_query($db, $query);
      $personaldetails = mysqli_fetch_assoc($result);
      return $personaldetails;
}

// escape string
function e($val){
      global $db;
      return mysqli_real_escape_string($db,trim($val));
}

function display_error() {
      global $errors;

      if (count($errors) > 0){
            echo '<div class="error">';
                  foreach ($errors as $error){
                        echo $error .'<br>';
                  }
            echo '</div>';
      }
}
?>
mark louieAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Peos JohnPHPCommented:
It looks like concatenation issue. Also please let us know what is the error you are getting.

can you try changing these lines like below
 if (isset($_POST['personal details'])) {
                  $user_type = e($_POST['personal details']);
                  $query = "INSERT INTO `personal details` (`IDNUMBER`, `username`, `Email`, `Phonenumber`, `country`, `book date`, `meals`, `number of guest`, `Room`, `Food menu`)
                  VALUES (NULL, '".$username."', '".$Email."', '".$Phonenumber."', '".$country."', '".$bookdate."', '".$meals."', '".$numberofguest."', '".$Room."', '".$Foodmenu."') ";
                  mysqli_query($db, $query);
                  $_SESSION['success']  = "New user successfully created!!";
                  header('HOME PAGE 1.HTML');
            }else{
                  $query = "INSERT INTO `personal details` (`IDNUMBER`, `username`, `Email`, `Phonenumber`, `country`, `book date`, `meals`, `number of guest`, `Room`, `Food menu`) 
                  VALUES (NULL, '".$username."', '".$Email."', '".$Phonenumber."', '".$country."', '".$bookdate."', '".$meals."', '".$numberofguest."', '".$Room."', '".$Foodmenu."') ";
                  mysqli_query($db, $query);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mark louieAuthor Commented:
i got no error on the code  and my database is still not receiving any data is there any possible reason? because i search the whole web about the problem but none are related to the problem i'm having.
0
Peos JohnPHPCommented:
Can you try enabling error reporting on the page ?

Please add these lines on top of your pages and see if you are getting any error.

ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);

Open in new window

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

mark louieAuthor Commented:
done no error on the page
0
Sam WallisIt/Web ManagerCommented:
Change your mysqli query line to
mysqli_query($db, $query) or die(mysqli_error($db));

Open in new window


This will let you know if there are any errors in your SQL syntax/query
0
mark louieAuthor Commented:
done and still no error and database is still not receiving data.
0
mark louieAuthor Commented:
errors that happen when i redo all the codesthis is my table in the serveri manage to redo all the codes i got 4 errors about undefined index does this mean i have to redo the database table?
updated codes
?php
    session_start();
      ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
      // connect to database
$db = mysqli_connect('localhost', 'root', '12345', 'hotel booking');

// variable declaration
$username = "";
$Email    = "";
$Phonenumber = "";
$country = "";
$bookdate ="";
$meals ="";
$numberofguest ="";
$Room ="";
$Foodmenu ="";
$errors = array();

// call the register() function if register_btn is clicked
if (isset($_POST['register_btn'])) {
      register();
}

// REGISTER USER
function register(){
      // call these variables with the global keyword to make them available in function
      global $db, $errors, $username, $Email, $Phonenumber, $country, $bookdate, $meals, $numberofguest, $Room, $Foodmenu;

      // receive all input values from the form. Call the e() function
    // defined below to escape form values

      $username    = e($_POST['username']);
      $Email       = e($_POST['Email']);
      $Phonenumber = e($_POST['Phonenumber']);
      $country     = e($_POST['country']);
    $bookdate    = e($_POST['bookdate']);
      $meals       = e($_POST['meals']);
      $numberofguest = e($_POST['numberofguest']);
      $Room = e($_POST['Room']);
      $Foodmenu = e($_POST['Foodmenu']);
      // form validation: ensure that the form is correctly filled
      if (empty($username)) {
            array_push($errors, "username is required");
      }
      if (empty($Email)) {
            array_push($errors, "Email is required");
      }
      if (empty($Phonenumber)) {
            array_push($errors, "Phonenumber is required");
    }
      if (empty($country)) {
            array_push($errors, "country is required");
    }
      if (empty($bookdate)) {
            array_push($errors, "bookdate is required");
    }
      if (empty($meals)) {
            array_push($errors, "meals is required");
    }
      if (empty($numberofguest)) {
            array_push($errors, "numberofguest is required");
    }
      if (empty($Room)) {
            array_push($errors, "Room is required");
    }
      if (empty($Foodmenu)) {
            array_push($errors, "Foodmenu is required");
    }
      // register user if there are no errors in the form
      

             if (isset($_POST['personal details'])) {
                  $user_type = e($_POST['personal details']);
                  $query = "INSERT INTO `personal details` (`IDNUMBER`, `username`, `Email`, `Phonenumber`, `country`, `bookdate`, `meals`, `numberofguest`, `Room`, `Foodmenu`)
                          VALUES (NULL, '$username', '$Email', '$Phonenumber', '$country', '$bookdate', '$meals', '$numberofguest', '$Room', '$Foodmenu') ";
                  mysqli_query($db, $query) or die(mysqli_error($db));
                  $_SESSION['success']  = "New user successfully created!!";
                  header("location:../booking.php");
            }else{
                  $query = "INSERT INTO `personal details` (`IDNUMBER`, `username`, `Email`, `Phonenumber`, `country`, `bookdate`, `meals`, `numberofguest`, `Room`, `Foodmenu`)
                          VALUES (NULL, '$username', '$Email', '$Phonenumber', '$country', '$bookdate', '$meals', '$numberofguest', '$Room', '$Foodmenu') ";
                  mysqli_query($db, $query) or die(mysqli_error($db));

                                    
            }

            }
      
// return user array from their id
function getUserById($username){
      global $db;
      $query = "SELECT * FROM `personal details` WHERE `username`=". $username;
      $result = mysqli_query($db, $query) or die(mysqli_error($db));
      $personaldetails = mysqli_fetch_assoc($result);
      return $personaldetails;
}

// escape string
function e($val){
      global $db;
      return mysqli_real_escape_string($db,trim($val));
}

function display_error() {
      global $errors;

      if (count($errors) > 0){
            echo '<div class="error">';
                  foreach ($errors as $error){
                        echo $error .'<br>';
                  }
            echo '</div>';
      }
}
?>
0
mark louieAuthor Commented:
thank you guys for your help and ideas i solved the problem and its working
1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.