I'm getting an error
Here's the code:
<?php
//db connection
$dbserv="localhost:3306";
$dbuser="root";
$dbpass="firepower";
$dbname="account_data";
$db_connect=new mysqli($dbserv, $dbuser, $dbpass, $dbname);
if($db_connect->connect_errno){
die("Error trying to connect to database");
}
session_start();
if(isset($_SESSION['current_page'])){
$prev_page=$_SESSION['current_page'];
$_SESSION['current_page'] = basename($_SERVER['PHP_SELF']);
}
else{
$prev_page='';
}
if(!isset($_SESSION['email'])){
header('location:'.'index.php?_rdr');
die();
}
$limit=$_SESSION['limit'];
$index=1;
$first=true;
$products_ordered='';
while($index<=$limit){
if(isset($_POST[$index]) && $first==true){
$products_ordered.=$_POST[$index].' x Pizza '.$_SESSION['prod_name'][$index];
$first=false;
}
else if(isset($_POST[$index]) && $first==false){
$products_ordered.=', '.$_POST[$index].' x Pizza '.$_SESSION['prod_name'][$index];
}
$index++;
}
//insert order into db
$user_email=$_SESSION['email'];
$total_price=$_SESSION['order_price'];
$query="INSERT INTO orders (email, products_ordered, total_price) VALUES (?, ?, ?)";
$sql_sec=$db_connect->prepare($query);
$sql_sec->bind_param("ssi", $user_email, $products_ordered, $total_price);
$sql_sec->execute();
$result=$sql_sec->get_result();
if(mysqli_num_rows($result)){
exit("Order added successfully!");
}
else{
exit("Error connecting to database!");
}
?>
It's so strange because data is added correctly to my database and the other times I used the same code (for user registration) it worked with no problems... I checked everything and I can't find the problem.
$query="INSERT INTO orders (email, products_ordered, total_price) VALUES (?, ?, ?)";
$sql_sec=$db_connect->prepare($query);
$sql_sec->bind_param("ssi", $user_email, $products_ordered, $total_price);
$sql_sec->execute();
$result=$sql_sec->get_result();
if(mysqli_num_rows($result)){
exit("Order added successfully!");
}
else{
exit("Error connecting to database!");
}
The error I'm getting is this:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\Dream Pizza\add_order.php on line 58
Error connecting to database!