Heres the code involved.
List box to display what the user may want to buy, these 2 scripts are on the same page! :
Code: Select all
<form name="Form1" method="POST" action="housepurchaseprocess.php" enctype="multipart/form-data" id="Form1" onsubmit="return ValidateForm1(this)">
<?php
$soldhousesquery = "SELECT Price, HouseType FROM soldhouses ORDER BY Price ASC";
$soldhousesresult = @mysql_query($soldhousesquery) or die(mysql_error());
echo '<select name="houselist" size=10>">';
while($soldhousesrow = mysql_fetch_array($soldhousesresult)) {
echo "<option value="{$soldhousesrow['Price']}|{$soldhousesrow['HouseType']}">£ {$soldhousesrow['Price']} - {$soldhousesrow['HouseType']}</option>";
}
echo '</select>';
?>
</div>
<input type="submit" id="Button2" name="Buy" value="Buy House" style="position:absolute;left:350px;top:600px;width:184px;height:24px;z-index:20">
</form>Code: Select all
<?
include ("include.php");
include ("energybarinclude.php");
session_start();
$_SESSION['Price'] = $soldhousesrow['Price'];
$_SESSION['HouseID'] = $soldhousesrow['SoldHouseID'];
$_SESSION['NumberOfRooms'] = $soldhousesrow['NumberOfRooms'];
$_SESSION['HouseType'] = $soldhousesrow['HouseType'];
?>Process page:
Code: Select all
<?
include ("include.php");
session_start();
$FindCityID = mysql_query("SELECT * FROM userregistration
WHERE UserID='{$_SESSION['Current_User']}'");
// Fetch the row from the database
if (!($row = mysql_fetch_assoc($FindCityID))) {
echo "City ID not found!";
exit;
echo mysql_error();
}
$Area = $_SESSION['Area'];
$Street = $_SESSION['Streetname'];
$HouseID = $_SESSION['SoldHouseID'];
$NumberOfRooms = $_SESSION['NumberOfRooms'];
$Price = $_SESSION['Price'];
$CityID = $row['CityID'];
$HouseType = $_SESSION['HouseType'];
$UserID = $_SESSION['Current_User'];
$Money = $row['MoneyInHand'];
Echo $CityID;
Echo $Price;
Echo '</br>';
print_r ($Price);
Echo '</br>';
Echo $HouseType;
Echo '</br>';
Echo $UserID;
Echo '</br>';
Echo $Money;
Echo '</br>';
Echo $HouseID;
Echo '</br>';
Echo $NumberOfRooms;
Echo '</br>';
Echo $Area;
Echo '</br>';
Echo $Street;
Echo '</br>';
If ($Money > $Price) {
$subtractMoney = "UPDATE userregistration SET MoneyInHand=MoneyInHand-$price WHERE UserID='{$_SESSION['Current_User']}'";
$result = mysql_query($addMoney) or die(mysql_error());
if (mysql_affected_rows() == 0)
{
die('Error ID 0001A, contact admin on the Civilian forums immediately about this error!');
}
{
$val = explode('|', $_POST['houselist']);
if (count($val))
{
$price = $val[0];
$houseType = $val[1];
}
}
$boughthouse = "INSERT INTO `houses` (CityID,HouseType,Price,StreetName,Area,UserID)
Values ('$CityID', '$HouseType', '$price', '$Street', '$Area', '$UserID')";
mysql_query($boughthouse) or die(mysql_error());
$Deletesoldhouses = "DELETE * FROM soldhouses
WHERE SoldHouseID = $HouseID";
mysql_query($Deletesoldhouses) or die(mysql_error());
header("Location: choosehousenumber.php");
}
Else {
Echo 'You do not have enough money, i guess you will have to go to a mortgage company!';
}
?>The large list of echo's is just to test the values,, "housetype" echo's fine but yet "price" does not .. nor does the $HouseID;
$price;
$NumberOfRooms;
Im finding it hard to work out why [s]cos[/s] because price especially is coming from same place as housetype but wont work yet housetype does... its deffinatly filled in table and its spelt correctly.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.
Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.