when you put how many cars you want to buy and hit buy the $row varible when inserting is blank i dont see why.
<?php
session_start();
include "inc/connect.php";
include "inc/functions.php";
?>
<?php
$id = $_SESSION['id'];
$data2 = mysql_fetch_assoc(mysql_query("SELECT * FROM members_data WHERE id='$id'"));
$userloc = location($data2[location]);
if($userloc == "London"){
$loc = "London";
$loc1 = "1";
}
else if($userloc == "Manchester"){
$loc = "Manchester";
$loc1 = "2";
}
else if($userloc == "Birmingham"){
$loc = "Birmingham";
$loc1 = "3";
}
else if($userloc == "Leeds"){
$loc = "Leeds";
$loc1 = "4";
}
else if($userloc == "Newcastle"){
$loc = "Newcastle";
$loc1 = "5";
}
else if($userloc == "Sydney"){
$loc = "Sydney";
$loc1 = "6";
}
else if($userloc == "Melbourne"){
$loc = "Melbourne";
$loc1 = "7";
}
else if($userloc == "Vancouver"){
$loc = "Vancouver";
$loc1 = "8";
}
else if($userloc == "New York"){
$loc = "New York";
$loc1 = "9";
}
else if($userloc == "Las Vegas"){
$loc = "Las Vegas";
$loc1 = "10";
}
$cars = array();
$sql = "SELECT * FROM car_available WHERE loc='$userloc' ORDER BY car_id";
$query = mysql_query($sql);
//mysql_free_result($query);
echo $sql;
echo $row[price];
?>
<head><link rel='stylesheet' type='text/css' href='../styles/in.css'></head>
<body>
<form action="" method="post">
<table width='90%' border='1' bordercolor='#000000' cellspacing='0'>
<tr>
<td colspan='11' background='../styles/gradient.jpg'><div align='center'>[LOCATION] Dealership</td>
</tr>
<tr>
<td>Car Name</td>
<td>Acceleration</td>
<td>Top Speed</td>
<td>Handling</td>
<td>Braking</td>
<td>Weight</td>
<td>Engine</td>
<td>Fuel</td>
<td>Stock</td>
<td>Price</td>
<td>Quantity</td>
</tr>
<?php
if($_POST['buy']){
$buy = array();
$cost = 0;
for ($i = 0, $c = count($_POST['carID']); $i < $c; ++$i) {
// Make sure the car ID is valid
if (empty($cars[$_POST['carID'][$i]])) continue;
// See if a positive amount was entered
$amount = empty($_POST['carAmount'][$i]) ? 0 : max(0, intval($_POST['carAmount'][$i]));
if (empty($amount)) continue;
// Make sure the specified amount is still available
if ($amount > $cars[$_POST['carID'][$i]]['quantity']) {
$error = true;
echo 'Not enough ' . $cars[$_POST['carID'][$i]]['car_name'] . ' left.';
break;
}
$buy[$_POST['carID'][$i]] = $amount;
echo $buy[$_POST['carID'][$i]];
if(!$row[price]){
echo "EMpty";
}
else{
echo $row['price'];
}
if(!$buy[$_POST['carID'][$i]]){
//nothing
}
else{
//$get = mysql_fetch_array(mysql_query("SELECT * FROM car_available WHERE car_id='{$_POST['carID']}'"));
}
$cost += $amount *$get['price'];
}
if (empty($error)) {
if ($data2['money'] < $cost) {
echo 'Not enough money';
}
else {
/*$newmoney = $data2['money']-$money;*/
$user = $data2['username'];
$newcara = mysql_query("UPDATE car_available SET quantity=quantity-'$amount' WHERE car_id='{$buy[$_POST['carID'][$i]]}' AND loc='$userloc'");
$in2 = mysql_query("INSERT INTO garage (`id`,`name`,`owner`, `value`,`damage`,`type`,`location`,`origin`,`acceleration`,`topspeed`,`handling`,`braking`,`weight`,`engine`,`fuel`) VALUES('','{$get['car_name']}','$user','{$get['price']}','0','1','$loc1','$loc1','{$get['acceleration']}','{$get['speed']}','{$get['handling']}','{$get[braking]}','{$get['weight']}','{$get['engine']}','{$get['fuel']}')")or die(mysql_error());
$in3 = mysql_query("UPDATE members_data SET money=money-'$cost' WHERE id='$id'")or die(mysql_error());
echo "You Bought" .$_POST['car']. "Of {$row['car_name']}" ;
}
}
}
//foreach ($cars as $carID => $row) {
while ($row = mysql_fetch_assoc($query)) {
echo "<tr>
<td>{$row['car_name']}</td>
<td>{$row['acceleration']}</td>
<td>{$row['speed']}</td>
<td>{$row['handling']}</td>
<td>{$row[braking]}</td>
<td>{$row['weight']}</td>
<td>{$row['engine']}</td>
<td>{$row['fuel']}</td>
<td>{$row['quantity']}</td>
<td>{$row['price']}</td>
<td><input type='hidden' name='carID[]' value='{$row[car_id]}' /><input name='carAmount[]' type='text' class='type' /></td> </tr>";
}
?>
</table>
<input type="submit" value="Buy it" name="buy" class='button' />
</form>
<?
?>