在插入数据库时遇到问题我运行到不同的mysqli
查询以插入到同一个表中,但在运行此插入到order_contents
所选的第二个查询时插入到不同的字段中运行var转储时,图像输出bool(false)
,不会插入数据库。
我已将下面的代码包含在内,以便可以看到。
<?php
session_start();
if($_GET['id']=='logout')
{
unset($_SESSION['userdetails']);
session_destroy();
}
require 'instagram.class.php';
require 'instagram.config.php';
if (!empty($_SESSION['userdetails'])) {
$data=$_SESSION['userdetails'];
// Store user access token
$instagram->setAccessToken($data);
} else
{
header('Location: index.php');
}
# Set page title and display header section.
$page_title = 'Checkout' ;
include ( 'includes/header.html' ) ;
# Check for passed total and cart.
if ( isset( $_GET['total'] ) && ( $_GET['total'] > 0 ) && (!empty($_SESSION['cart']) ) )
{
# Open database connection.
require ('connect_db.php');
# Store buyer and order total in 'orders' database table.
$q = "INSERT INTO orders ( id, total, order_date ) VALUES (".$data->user->id.",".$_GET['total'].", NOW() ) ";
$r = mysqli_query ($connection, $q);
var_dump($q);
# Retrieve current order number.
$order_id = mysqli_insert_id($connection) ;
# Retrieve cart items from 'shop' database table.
$q = "SELECT * FROM shop WHERE item_id IN (";
foreach ($_SESSION['cart'] as $id => $value) { $q .= $id . ','; }
$q = substr( $q, 0, -1 ) . ') ORDER BY item_id ASC';
$r = mysqli_query ($connection, $q);
# Store order contents in 'order_contents' database table.
while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC))
{
$query = "INSERT INTO order_contents ( order_id, item_id, quantity, price )
VALUES ( $order_id, ".$row['item_id'].",".$_SESSION['cart'][$row['item_id']]['quantity'].",".$_SESSION['cart'][$row['item_id']]['price'].")" ;
$result = mysqli_query($connection,$query);
}
var_dump($query);
# Display order number.
echo "<p>Thanks for your order. Your Order Number Is #".$order_id."</p>";
# Remove cart items.
$_SESSION['cart'] = NULL ;
}
# Or display a message.
else { echo '<p>There are no items in your cart.</p>' ; }
if (!isset($_SESSION['myvar']) ){
} else {
$q = "INSERT INTO order_contents ( selectedimages ) VALUES (".$_SESSION['myvar']['0'].") ";
$r = mysqli_query ($connection, $q);
var_dump($q);
var_dump($r);
var_dump($query);
mysqli_close($connection);
# Close database connection.
}
# Create navigation links.
echo '<p><a href="shop.php">Shop</a> | <a href="forum.php">Forum</a> | <a href="home.php">Home</a> | <a href="goodbye.php">Logout</a></p>' ;
# Display footer section.
include ( 'includes/footer.html' ) ;
?>