Hi all,
I'm having trouble inserting some of the data into a mySQL DB.
Lets say the user has ordered 3 DVD titles, 1 movieA, 2 movieB's and 1 movieC.
When it comes to this part of the script:
$result_2 = mysql_query("insert into orders(order_id,
customer_id, movie_id, movie_title, movie_current_price, qty,
order_date) values ('NULL', '" . $_SESSION['customer_id'] . "',
'$movie_id', '$movie_title', '$movie_current_price', '$qty',
'" . date('Ymd') . "')");
it only inserts the first two movie title.
Can anyone tell me why movieC and it's data arn't being inserted along with the other data?
I hope that makes sense, if it doesn't please ask questions and i will try and explain it a little better.
Here's the rest of the code:
<?
session_start();
if(isset($_POST['add_data'])) {
$db = mysql_connect("localhost", "", "");
mysql_select_db("swiftflix_sell",$db);
$result = mysql_query("insert into shipping(shipping_id,
customer_id, shipping_first_name, shipping_last_name,
shipping_address_1, shipping_address_2, shipping_city,
shipping_state, shipping_post_code, shipping_phone,
billing_address)
values('NULL', '" . $_SESSION['customer_id'] . "', '" . $_SESSION['shipping'][0] . "',
'" . $_SESSION['shipping'][1] . "', '" . $_SESSION['shipping'][2] . "', '" . $_SESSION['shipping'][3] . "',
'" . $_SESSION['shipping'][4] . "', '" . $_SESSION['shipping_state'] . "', '" . $_SESSION['shipping'][5] . "',
'" . $_SESSION['shipping'][6] . "', '" . $_SESSION['billing_address'] . "')");
if($_SESSION['billing_address'] == 'N'){
$result_1 = mysql_query("insert into billing(billing_id,
customer_id, billing_first_name, billing_last_name,
billing_address_1, billing_address_2, billing_city, billing_state,
billing_post_code, billing_phone)
values('NULL', '" . $_SESSION['customer_id'] . "',
'" . $_SESSION['billing'][0] . "', '" . $_SESSION['billing'][1] . "', '" . $_SESSION['billing'][2] . "', '" . $_SESSION['billing'][3] . "',
'" . $_SESSION['billing'][4] . "', '" . $_SESSION['billing_state'] . "', '" . $_SESSION['billing'][5] . "',
'" . $_SESSION['billing'][6] . "')");
}
include 'functions.php';
$i=0;
$subtotal = 0;
foreach ($_SESSION['cart'] as $_GET['isbn'] => $qty)
{
$_SESSION['total_price']=calculate_price($_SESSION['cart']);
$_SESSION['items']=calculate_items($_SESSION['cart']);
$sql = "SELECT movie_id,movie_title FROM movie WHERE movie_id='" . $_GET['isbn'] . "'";
$sql_result = mysql_query($sql) or die ("Could not select data");
while ($row = mysql_fetch_row($sql_result))
{
$movie_id = $row[0];
$movie_title = $row[1];
}
$sql2 = "SELECT * FROM movie_status WHERE movie_id='" . $_GET['isbn'] . "'";
$sql_result2 = mysql_query($sql2) or die ("Could not select data");
while ($row = mysql_fetch_row($sql_result2))
{
$movie_current_price = $row[3];
}
echo "$movie_id<br>";
echo "$movie_title<br>";
echo "$movie_current_price<br>";
$result_2 = mysql_query("insert into orders(order_id, customer_id, movie_id,
movie_title, movie_current_price, qty, order_date)
values ('NULL', '" . $_SESSION['customer_id'] . "', '$movie_id', '$movie_title',
'$movie_current_price', '$qty', '" . date('Ymd') . "')");
}
if($result || $result_1 || $result_2){
echo "Your data was successfully uploaded";
} else {
echo "Your data could not be uploaded";
}
} else {
// Form etc. goes here
}
?>
Cheers,
chrima