I want to get single value from phpmyadmin database table but i am getting these two errors.I am working on a ecommerce website and in this code i am trying to get a quantity value from the cart table and save it on the local variable and then insert it on the Order detail table
***Connection***
<?php
$servername = "localhost";
$username = "root";
$password = ""; // set this field "" (empty quotes) if you have not set any password in mysql
$dbname = "ecommerce";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//echo "Connection successful";
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
***Errors***
Warning: mysqli_query() expects parameter 1 to be mysqli
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result
***Code Where Error Exists***
$run_cart=mysqli_query($conn,"Select qty from cart vistor_id='$id'");
$get_qty=mysqli_fetch_array($run_cart);
echo $run_cart;
***All Code Here***
global $conn;
session_start();
if(!isset($_SESSION['loggedin']))
{
echo "<script language=\"javascript\"type=\"text/javascript\">window.location.href=\"login.php\";</script>";
exit(0);
}
$id =0.0;
if(isset($_COOKIE['vistor_id']))
{
$id=$_COOKIE['vistor_id'];
}
include("db/opendb.php");
include("db/functions.php");
$date=date('Y-m-d H:i:s');
$run_cart=mysqli_query($conn,"Select qty from cart vistor_id='$id'");
$get_qty=mysqli_fetch_array($run_cart);
echo $run_cart;
$msg = NULL;
$dbobj = new Database();
$dbobj1 = new Database();
$query = "insert into order_t(order_des,order_date, fuser_name) values ('order placed at $date', '$date', '".$_SESSION['s_username']."')";
$msg = $dbobj -> UpdateRecord($query, "Inserted");
$orderid=$conn->lastInsertId();
$query="select Product_id from cart where vistor_id='".$id."'";
$dbobj -> FetchRecord($query);
while($row = $dbobj->pstmt->fetch())
{
$query = "insert into order_detail(forder_id,fproduct_id,qty) values ('$orderid', '$row[0]','$qty')";
$msg = $dbobj1 -> UpdateRecord($query, "Inserted");
}
$dbobj -> CloseDBCon();
//echo "<script language=\"javascript\" type=\"text/javascript\">window.location.href=\"CheckoutComplete.php\";</script>";
//exit(0);
return
Aucun commentaire:
Enregistrer un commentaire