-
February 10th, 2012, 03:02 PM
#1
help!
Hi I am pretty bad at php but I have got an error message as below:
Fatal error: Call to a member function hook_exist() on a non-object in /home/xxxxxxx/public_html/xxxxxxx/api/business.class.php on line 495
the code below is referring to the error
Code:
function processBooking(){
// rather than recursively calling query, insert all rows with one query
GLOBAL $general, $global_basedir;
// database table to store reservations
$table ='reservations';
// reservation date
$reservation_date = $_SESSION['selectedDate'];
// prepare POST data for storage in database:
// $keys
// $values
if( $_POST['action'] == 'submit') {
$keys = array();
$values = array();
$i=1;
// prepare arrays for database query
foreach($_POST as $key => $value) {
if( $key != "action"
&& $key != "dbdate"
&& $key != "reservation_date"
&& $key != "recurring_dbdate"
&& $key != "captcha"
&& $key != "barrier"
&& $key != "reservation_author"
&& $key != "email_type"
&& $key != "terms"
&& $key != "captchaField1"
&& $key != "captchaField2"
&& $key != "captchaField3"){
$keys[$i] = $key;
$values[$i] = "'".$value."'";
}
// remember some values
if( $key == "reservation_date" ){
$reservation_date = strtotime($value);
}else if($key == 'reservation_booker_name'){
$_SESSION['author'] = $value;
}else if($key == 'reservation_time'){
$_SESSION['reservation_time'] = "'".$value."'";
}else if($key == 'reservation_pax'){
$_SESSION['reservation_pax'] = "'".$value."'";
}
if( $key == "reservation_date" ){
$keys[$i] = $key;
$values[$i] = "'".$_SESSION['selectedDate']."'";
}
$i++;
} // END foreach $_POST
// =-=-=-=Store in database =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// clear old booking number
$_SESSION['booking_number'] = '';
// variables
$res_pax = ($_POST['reservation_pax']) ? (int)$_POST['reservation_pax'] : 0;
// sanitize old booking numbers
$clr = querySQL('sanitize_unique_id');
// create and store booking number
if (!$_POST['reservation_id'] || $_POST['reservation_id']=='') {
$_SESSION['booking_number'] = uniqueBookingnumber();
//$_SESSION['messages'][] = _booknum.": ' ".$_SESSION['booking_number']." '";
$keys[] = 'reservation_bookingnumber';
$values[] = "'".$_SESSION['booking_number']."'";
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// enter into database
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// build new reservation date
$index = array_search('reservation_date',$keys);
// build for availability calculation
$index = array_search('reservation_wait',$keys);
if($index){
$values[$index] = '1';
$waitlist = '1';
}
//Check Availability
// =-=-=-=-=-=-=-=-=
// get Pax by timeslot
$resbyTime = reservationsByTime('pax');
$tblbyTime = reservationsByTime('tbl');
// get availability by timeslot
$occupancy = getAvailability($resbyTime,$general['timeintervall']);
$tbl_occupancy = getAvailability($tblbyTime,$general['timeintervall']);
//cut both " ' " from reservation_pax
$res_pax = substr($_SESSION['reservation_pax'], 0, -1);
$res_pax = substr($_SESSION['reservation_pax'], 1);
$startvalue = $_SESSION['reservation_time'];
//cut both " ' " from reservation_time
$startvalue = substr($startvalue, 0, -1);
$startvalue = substr($startvalue, 1);
$val_capacity = $_SESSION['outlet_max_capacity']-$occupancy[$startvalue];
$tbl_capacity = $_SESSION['outlet_max_tables']-$tbl_occupancy[$startvalue];
if( (int)$res_pax > $val_capacity || $tbl_capacity < 1 ){
//prevent double entry
$index = array_search('reservation_wait',$keys);
if($index>0){
$values[$index] = '1'; // = waitlist
$waitlist = '1';
}else{
// error on new entry
$keys[] = 'reservation_wait';
$values[] = '1'; // = waitlist
$waitlist = '1';
}
}
// END Availability
if ($waitlist != 1){
// number of database fields
$max_keys = count($keys);
// enter into database
// -----
$query = "INSERT INTO `$table` (".implode(',', $keys).") VALUES (".implode(',', $values).") ON DUPLICATE KEY UPDATE ";
// Build 'on duplicate' query
for ($i=1; $i <= $max_keys; $i++) {
if($keys[$i]!=''){
$query .= $keys[$i]."=".$values[$i].",";
}else{
$max_keys++;
}
}
// run sql query
$query = substr($query,0,-1);
$result = query($query);
$_SESSION['result'] = $result;
// Reservation ID
$resID = mysql_insert_id();
// *** send confirmation email
// ** PHPMailer class
require('../web/classes/phpmailer/class.phpmailer.php');
// ** plugin hook
if ($hook->hook_exist('after_booking')) {
$hook->execute_hook('after_booking');
}
// store new reservation in history
$result = query("INSERT INTO `res_history` (reservation_id,author) VALUES ('%d','%s')",$resID,$_SESSION['author']);
// Reservation was done
$waitlist = 2;
}
// reservation done, handle back waitlist status
return $waitlist;
}
}
Last edited by Cimperiali; February 10th, 2012 at 08:49 PM.
Reason: added [code][/code] tags
-
February 11th, 2012, 11:12 PM
#2
Re: help!
Welcome to the forums, steinm! Please remember to search before posting. This is the #1 most commonly asked question here at CodeGuru.
(1) Either the variable your treating as an object is of the object type or (2) it hasn't been created yet.
In your case, it's #2...there's no reference to $hook being created at all.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|