thoford75
12-07-2010, 05:06 PM
Hi all. Very quick question (I hope!)
I'm trying to post some values to my database onsubmit.
The field names in the db are correct and the first two values sumbit (the id and product number)
Here is the complete php code. Really appreciate any help as this is driving me crazy!!
<?php session_start();
if (isset($_SESSION['again'])) {
$again = $_SESSION['again'];
unset($_SESSION['again']);
}
// Include the MySQL Connect file.
include('admin/components/mysql_connect.inc');
// Include a function to build the URL.
include('components/build-url.php');
// Include the code to build the query.
include('components/build-query.php');
// Ensure there's an ID and validate it
if (!isset($_GET['carpet']) || !is_numeric($_GET['carpet'])) {
header('Location: /results.php');
exit;
}
else {
$id = $_GET['carpet'];
$query = "SELECT products.*, ranges.*, manufacturers.*, piles.* FROM products, ranges, manufacturers, piles WHERE products.range_id=ranges.range_id AND ranges.manufacturer_id=manufacturers.manufacturer_id AND ranges.pile_id=piles.pile_id AND products.product_id=" . mysql_real_escape_string($id);
$result = mysql_query($query);
if (mysql_num_rows($result) != 1) {
header('Location: /results.php');
exit;
}
else {
$row = mysql_fetch_assoc($result);
$product_image = $row['product_image'];
$product_name = $row['product_name'];
$range_name = $row['range_name'];
$product_description = $row['product_description'];
$range_on_sale = $row['range_on_sale'];
$range_resell_price = $row['range_resell_price'];
$range_sale_discount = $row['range_sale_discount'];
$manufacturer_name = $row['manufacturer_name'];
$range_backing = $row['range_backing'];
$range_width = $row['range_width'];
$pile_name = $row['pile_name'];
$range_warranty = $row['range_warranty'];
$range_british_wool = $row['range_british_wool'];
$room_id = $row['room_id'];
$range_id = $row['range_id'];
$query2 = "SELECT * FROM fitting WHERE fitting_id=1";
$result2 = mysql_query($query2);
$row2 = mysql_fetch_assoc($result2);
$fitting_price = $row2['fitting_price'];
}
}
if ($_GET['unknown']) {
// Ensure there's an ID and validate it
if (!isset($_GET['carpet']) || !is_numeric($_GET['carpet'])) {
header('Location: /results.php');
exit;
}
if ($range_on_sale == 'Y') {
$basket_carpet_price = number_format($range_resell_price/100*(100-$range_sale_discount), 2);
}
else {
$basket_carpet_price = $range_resell_price;
}
$query = sprintf("INSERT INTO basket (product_id, basket_name, session_id, ) VALUES ('$id', '%s', '%s')",
mysql_real_escape_string(stripslashes(strip_tags($_POST['roomsize']))),
mysql_real_escape_string(session_id()));
$result = mysql_query($query);
$_SESSION['url'] = $_SERVER['REQUEST_URI'];
$_SESSION['just_added'] = $_GET['carpet'];
$_SESSION['room_name'] = 'Unnamed Room';
$_SESSION['unknown'] = 'Y';
header('Location: /basket.php');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
</head>
<body>
<form action="" method="post" name="confirm_form">
<select name="roomsize" size="1">
<option value="Living Room" <?php if ($_POST['roomsize'] == 'Living Room') { echo 'selected="selected"'; } ?>>Living Room</option>
<option value="Bedroom 1" <?php if ($_POST['roomsize'] == 'Bedroom 1') { echo 'selected="selected"'; } ?>>Bedroom 1</option>
<option value="Bedroom 2" <?php if ($_POST['roomsize'] == 'Bedroom 2') { echo 'selected="selected"'; } ?>>Bedroom 2</option>
</select>
</form>
<?php
if ($_SESSION['unknown']) {
echo '<a href="1702.php?carpet=' . $id . '&unknown=y" target="_parent"><img src="/images/basketlink.jpg" border="0" alt="ADD >" title="ADD >" /></a>';
}
else {
echo '<a href="1702.php?carpet=' . $id . '&unknown=y" target="_parent"><img src="/images/basketlink.jpg" border="0" alt="ADD >" title="ADD >" /></a>';
}
?>
</body>
</html>
I'm trying to post some values to my database onsubmit.
The field names in the db are correct and the first two values sumbit (the id and product number)
Here is the complete php code. Really appreciate any help as this is driving me crazy!!
<?php session_start();
if (isset($_SESSION['again'])) {
$again = $_SESSION['again'];
unset($_SESSION['again']);
}
// Include the MySQL Connect file.
include('admin/components/mysql_connect.inc');
// Include a function to build the URL.
include('components/build-url.php');
// Include the code to build the query.
include('components/build-query.php');
// Ensure there's an ID and validate it
if (!isset($_GET['carpet']) || !is_numeric($_GET['carpet'])) {
header('Location: /results.php');
exit;
}
else {
$id = $_GET['carpet'];
$query = "SELECT products.*, ranges.*, manufacturers.*, piles.* FROM products, ranges, manufacturers, piles WHERE products.range_id=ranges.range_id AND ranges.manufacturer_id=manufacturers.manufacturer_id AND ranges.pile_id=piles.pile_id AND products.product_id=" . mysql_real_escape_string($id);
$result = mysql_query($query);
if (mysql_num_rows($result) != 1) {
header('Location: /results.php');
exit;
}
else {
$row = mysql_fetch_assoc($result);
$product_image = $row['product_image'];
$product_name = $row['product_name'];
$range_name = $row['range_name'];
$product_description = $row['product_description'];
$range_on_sale = $row['range_on_sale'];
$range_resell_price = $row['range_resell_price'];
$range_sale_discount = $row['range_sale_discount'];
$manufacturer_name = $row['manufacturer_name'];
$range_backing = $row['range_backing'];
$range_width = $row['range_width'];
$pile_name = $row['pile_name'];
$range_warranty = $row['range_warranty'];
$range_british_wool = $row['range_british_wool'];
$room_id = $row['room_id'];
$range_id = $row['range_id'];
$query2 = "SELECT * FROM fitting WHERE fitting_id=1";
$result2 = mysql_query($query2);
$row2 = mysql_fetch_assoc($result2);
$fitting_price = $row2['fitting_price'];
}
}
if ($_GET['unknown']) {
// Ensure there's an ID and validate it
if (!isset($_GET['carpet']) || !is_numeric($_GET['carpet'])) {
header('Location: /results.php');
exit;
}
if ($range_on_sale == 'Y') {
$basket_carpet_price = number_format($range_resell_price/100*(100-$range_sale_discount), 2);
}
else {
$basket_carpet_price = $range_resell_price;
}
$query = sprintf("INSERT INTO basket (product_id, basket_name, session_id, ) VALUES ('$id', '%s', '%s')",
mysql_real_escape_string(stripslashes(strip_tags($_POST['roomsize']))),
mysql_real_escape_string(session_id()));
$result = mysql_query($query);
$_SESSION['url'] = $_SERVER['REQUEST_URI'];
$_SESSION['just_added'] = $_GET['carpet'];
$_SESSION['room_name'] = 'Unnamed Room';
$_SESSION['unknown'] = 'Y';
header('Location: /basket.php');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
</head>
<body>
<form action="" method="post" name="confirm_form">
<select name="roomsize" size="1">
<option value="Living Room" <?php if ($_POST['roomsize'] == 'Living Room') { echo 'selected="selected"'; } ?>>Living Room</option>
<option value="Bedroom 1" <?php if ($_POST['roomsize'] == 'Bedroom 1') { echo 'selected="selected"'; } ?>>Bedroom 1</option>
<option value="Bedroom 2" <?php if ($_POST['roomsize'] == 'Bedroom 2') { echo 'selected="selected"'; } ?>>Bedroom 2</option>
</select>
</form>
<?php
if ($_SESSION['unknown']) {
echo '<a href="1702.php?carpet=' . $id . '&unknown=y" target="_parent"><img src="/images/basketlink.jpg" border="0" alt="ADD >" title="ADD >" /></a>';
}
else {
echo '<a href="1702.php?carpet=' . $id . '&unknown=y" target="_parent"><img src="/images/basketlink.jpg" border="0" alt="ADD >" title="ADD >" /></a>';
}
?>
</body>
</html>