Fatal error: Uncaught Error: Call to a member function


#11

now i have this Fatal error : Uncaught mysqli_sql_exception: Column count doesn’t match value count at row 1 in C:\xampp\htdocs\carbooking3\16 y\korak1.php:27 Stack trace: #0 C:\xampp\htdocs\carbooking3\16 y\korak1.php(27): mysqli->prepare(‘INSERT INTO ca…’) #1 {main} thrown in C:\xampp\htdocs\carbooking3\16 y\korak1.php on line 27


#13

Show us the code that is throwing this error.


#14
$mysqli = new mysqli('localhost', 'root', '', 'cars123');

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
// prepare and bind
/*<?php ?> $start_date=$_POST['start_date'];
$end_date=$_POST['end_date'];
$cars=$_POST['cars'];
$Location_of_renting=$_POST['Location_of_renting'];
$Location_of_returning=$_POST['Location_of_returning'];
<?php ?>*/


global $connect;
$stmt = $mysqli->prepare("INSERT INTO  cars321 VALUES (?,?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param('sssssssss', $id,$start_date, $end_date, $cars, $Location_of_renting,$Location_of_returning,$vr_uzi,$vr_vraca,$paid);	 

$start_date = '2018-09-20';
$end_date= '2018-09-21';
$cars = "1";
$Location_of_renting= '2018-09-16 13:50:27
';
$Location_of_returning= '2018-09-16 13:50:29
';
$vr_uzi= 'mostar';
$vr_vraca= 'modstar';
$paid= '1';
/* execute prepared statement */
$stmt->execute();

printf("%d Row inserted.\n", $stmt->affected_rows);

/* close statement and connection */
$stmt->close();

/* Clean up table CountryLanguage */


/* close connection */
$mysqli->close();

CREATE TABLE `cars321` (
  `id` int(11) NOT NULL,
  `start_date` date NOT NULL,
  `end_date` date NOT NULL,
  `cars` int(11) NOT NULL,
  `Location_of_renting` text NOT NULL,
  `Location_of_returning` text NOT NULL,
  `vr_uzi` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `vr_vraca` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
  `paid` int(11) NOT NULL DEFAULT '1',
  `price` int(11) NOT NULL,
  `numberdays` int(11) NOT NULL,
  `Numbers_of_cars` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Fatal error : Uncaught Error: Call to a member function bind_param() on boolean in C:\xampp\htdocs\carbooking3\16 y\korak1.php:28 Stack trace: #0 {main} thrown in C:\xampp\htdocs\carbooking3\16 y\korak1.php on line 28
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$stmt->bind_param('sssssssss', $id,$start_date, $end_date, $cars, $Location_of_renting,$Location_of_returning,$vr_uzi,$vr_vraca,$paid); line **28**


#15

(I really meant show the code that throws the error and a bit of related, not the entire thing).

Is it correct to specify the “id” field using an “s” marker when you’ve defined it in the table as an integer? Surely you should pass it as an integer. I can’t see where you define $id anywhere, though.

As mentioned before, though, if you’re not going to specify the column names that you’re inserting values into, then you have to give values for every column. You have 12 columns in the table, and 9 values in the query. You’ve said that the columns cannot be null, you haven’t specified a value for them, what can MySQL do other than reject the query?


#16

cant go on next page


#17

Sorry, no idea what you mean by that comment.


#18

$insertGoTo = ‘korak22.php?id=’;


#19

korak1.php I am here cant go on $insertGoTo = ‘korak22.php?id=’;


#20

the code was in mysql i am changing in mysqli how to go on next page in mysqli.


#21

What does this have to do with the error message you posted in post #14? Or have you fixed that one now.

Or do you mean that you pass the value for $id in as part of the URL? If that’s it, you need to extract it from the $_GET array before you use it. But I still don’t think it should be a string.


#22

mysqli has nothing to do with header redirects, I am not sure what you mean. Is the query that was giving you an error now working?


#23

no error


#24

Ah, OK, so you’re trying to sort something different out now? That would be good to mention. Can you explain in a bit more detail what problem you are having now, with the failing code?


#25

after insert data in db cant on next page every time refreshing page new data go in db.


#26

There is no redirect in your code.

Also, bind_values is better than bind_params as it’s easy to create bugs with bind_params


#27
$mysqli = new mysqli('localhost', 'root', '', 'cars123'); 

/* check connection */ 
if (mysqli_connect_errno()) { 
    printf("Connect failed: %s\n", mysqli_connect_error()); 
    exit(); 
} 
// prepare and bind 
/*<?php ?> $start_date=$_POST['start_date']; 
$end_date=$_POST['end_date']; 
$cars=$_POST['cars']; 
$Location_of_renting=$_POST['Location_of_renting']; 
$Location_of_returning=$_POST['Location_of_returning']; 
<?php ?>*/ 


global $connect; 
$stmt = $mysqli->prepare("INSERT INTO  cars321 VALUES (?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); 
$stmt->bind_param('ssssssssssss', $id,$start_date, $end_date, $cars, $Location_of_renting,$Location_of_returning,$vr_uzi,$vr_vraca,$paid,$price ,$numberdays    ,$Numbers_of_cars);      

$start_date = '2018-09-20'; 
$end_date= '2018-09-21'; 
$cars = "1"; 
$Location_of_renting= '2018-09-16 13:50:27 
'; 
$Location_of_returning= '2018-09-16 13:50:29 
'; 
$vr_uzi= 'mostar'; 
$vr_vraca= 'modstar'; 
$paid= '1'; 
$price= '111'; 
$numberdays= '11'; 
$Numbers_of_cars= '1'; 


/* execute prepared statement */ 
$stmt->execute(); 

printf("%d Row inserted.\n", $stmt->affected_rows); 

/* close statement and connection */ 
$stmt->close(); 

/* Clean up table CountryLanguage */ 


/* close connection */ 

  
  
  
  
  $get_max_id =$link->prepare('SELECT start_date, end_date, cars FROM cars321 WHERE id = (SELECT MAX(ID) FROM cars321);');   
  echo 'Error: ' . mysqli_error($link); 
   
   
  $query="UPDATE cars321  SET vr_uzi=NOW() WHERE vr_uzi=0000-00-00 00:00:00"; 
   $query="UPDATE cars321  SET vr_vraca=NOW() WHERE vr_vraca=0000-00-00 00:00:00";     
   
   
  $get_max_id->execute(); 
  
  $get_max_id->fetch(); 
  $get_max_id->close(); 
  $insertGoTo = 'korak22.php?id='; 
/* 
  if (isset($_SERVER['QUERY_STRING'])) { 
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; 
    $insertGoTo .= $_SERVER['QUERY_STRING']; 
  } 
*/ 
 $mysqli->close();
```CREATE TABLE `cars321` ( 
  `id` int(11) NOT NULL, 
  `start_date` date NOT NULL, 
  `end_date` date NOT NULL, 
  `cars` int(11) NOT NULL, 
  `Location_of_renting` text NOT NULL, 
  `Location_of_returning` text NOT NULL, 
  `vr_uzi` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 
  `vr_vraca` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, 
  `paid` int(11) NOT NULL DEFAULT '1', 
  `price` int(11) NOT NULL, 
  `numberdays` int(11) NOT NULL, 
  `Numbers_of_cars` int(11) NOT NULL 
) ENGINE=InnoDB DEFAULT CHARSET=latin1  

cant insert in db also go on next page:thinking:

#28

<button id=“btn_room_search” action=“http://localhost/carbooking3/16%20y/korak22.php"class="sear-btn” type=“submit”>Search


#29

with this code i have on next page but cant insert in db

               <button id="btn_room_search" class="sear-btn" type="submit"><a href="http://localhost/carbooking3/16%20y/korak22.php?id=">Search</a></button>

#30

just one insert could do after that nothing


#32
$db = new PDO("mysql:host=localhost;dbname=$cars123", "", "");
//Add session_start to top of each page//
}



if (isset($_POST['btn_room_search'])){
	$query = $db->prepare("INSERT INTO cars321 (id,start_date,end_date,cars,Location_of_renting,Location_of_returning,vr_uzi,vr_vraca,paid,price,numberdays,Numbers_of_cars) 
	
	
	
	VALUES(:id,:start_date,:end_date,:cars,:Location_of_renting,:Location_of_renting,:vr_uzi,:vr_vraca,:paid,:price,:numberdays,:Numbers_of_cars))");
	$query->bindParam(":id", $_POST['id']);
	$query->bindParam(":start_date", $_POST['start_date']);
	$query->bindParam(":end_date", $_POST['end_date']);
	$query->bindParam(":cars", $_POST['cars']);
		$query->bindParam(":Location_of_renting", $_POST['Location_of_renting']);
	$query->bindParam(":Location_of_returning", $_POST['Location_of_returning']);
	$query->bindParam(":vr_uzi", $_POST['vr_uzi']);
	$query->bindParam(":vr_vraca", $_POST['vr_vraca']);
	
	$query->bindParam(":paid", $_POST['paid']);
	$query->bindParam(":price", $_POST['price']);
	$query->bindParam(":numberdays", $_POST['numberdays']);
	$query->bindParam(":Numbers_of_cars", $_POST['Numbers_of_cars']);
	
	
	$query->execute();
}

i tried like that no inserting