-2

I am experiencing an issue with this error, The code I have used is given below:

<?php
$cus_name = isset($_POST['client_name'])?$_POST['client_name']:'';
$description = isset($_POST['desc'])?$_POST['desc']:'';
$amount = isset($_POST['amnt'])?$_POST['amnt']:'';

$query = "INSERT INTO ".$RECORD_TABLE."(cus_name,description,amount) VALUES ('$cus_name','$description','$amount') " ;
$result = mysqli_query($dbObj,$query);

if(!$result)
{
  echo "error while inserting";
}


?>

That is the code I am using for insertion of date into the database. The connection code I am giving below:

$DB_HOST = 'localhost';
$DB_USER = 'root';
$DB_PWD = '';
$DB_NAME = 'hotel_booking';

$BOOKING_TABLE = 'hotel_booking';
$PRICING_TABLE = 'hotel_pricing';
$SETTING_TABLE = 'hotel_setting';
$RECORD_TABLE = 'hotel_record';
require_once('Database.class.php');

global $dbObj;
$dbObj = new Database($DB_HOST,$DB_USER,$DB_PWD,$DB_NAME,1,0);
DEV
  • 647
  • 4
  • 19
  • 31

3 Answers3

1

I think you problem is for connection Try this code

$conn = mysqli_connect($DB_HOST,$DB_USER,$DB_PWD,$DB_NAME);

and also change

$query = "INSERT INTO ".$RECORD_TABLE."(cus_name,description,amount) VALUES ('".$cus_name."','".$description."','".$amount."') " ;
$result = $conn->query($query);
Shaymol Bapary
  • 468
  • 3
  • 11
0

Now your $dbObj is an object of Database class. If you waht to use with mysqli_*, then $dbObj should be like this.

$dbObj = mysqli_connect("host", "user", "password","database name");

See here for more info.

Niranjan N Raju
  • 12,047
  • 4
  • 22
  • 41
-2

check whether class returns new mysqli

 class Database() {
    function __constructor(){
        $obj=mysqli_connect($DB_HOST,$DB_USER,$DB_PWD,$DB_NAME);
        return $obj;
    }
 }
Sugumar Venkatesan
  • 4,019
  • 8
  • 46
  • 77