All pastes #754098 Raw Edit

Untitled

public text v1 · immutable
#754098 ·published 2007-10-29 19:46 UTC
rendered paste body
<?php

session_start();

include "inc/connect.php";
include "inc/functions.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); 
while ($row = mysql_fetch_assoc($query)) $cars[$row['car_id']] = $row;
mysql_free_result($query);

?>
<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;
  } // for

  // Add products to order
  $buy[$_POST['carID'][$i]] = $amount;
  $cost += $amount *$get['price'];
 }

 if (empty($error)) {
  if ($data2['money'] < $cost) {
   echo 'Not enough money';
  }
  else {
   $r = mysql_query("UPDATE members_data SET money = money - $cost WHERE id = $id AND money >= $cost");
   if ($r && mysql_affected_rows() == 1) {
    foreach ($buy as $id => $amount) {
     mysql_query("UPDATE `car_available` SET `quantity`=`quantity`-$amount WHERE `car_id`=$id AND `loc`='$userloc'");
     mysql_query("INSERT INTO `garage`(`car_id`,`owner`,`value`,`damage`,`type`,`location`,`origin`,`acceleration`,`topspeed`,`handling`,`braking`,`weight`,`engine`,`fuel`) 
	 VALUES('{$cars[$id]['car_id']}','{$data2['username']}','{$cars[$id]['price']}','0','1','$userloc','$userloc','{$cars[$id]['acceleration']}','{$cars[$id]['speed']}','{$cars[$id]['handling']}','{$cars[$id]['braking']}','{$cars[$id]['weight']}','{$cars[$id]['engine']}','{$cars[$id]['fuel']}')");
     echo "You bought $amount of {$cars[$id]['car_name']}<br />" ;
    } // foreach
   } // if ($r && mysql_affected_rows() == 1)
  } // if ($data2['money'] < $cost)
 } // if (empty($error))
} // if($_POST['buy'])

foreach ($cars as $carID => $row) {
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>