Jump to content

Recommended Posts

i have a script which creates 2 variables which then does a redirect to a page which then uses a query using the two variables. But i was wondering how to get the code to pass across the page...

 

Also just to add i think my query is not working which is part of this....

 

<?
include ("include.php");

if (isset($_POST['ShowHouses'])) {
$Area = ($_POST['RegionComboBox']);
$StreetName = ($_POST['StreetComboBox']);
header("Location: housepurchaselist.php");
}
?>

 

On the housepurchaselist.php i have this query but its not working :S:

 

<?


Echo '<select name="Combobox3" size="2" id="Combobox3" style="position:absolute;left:343px;top:520px;width:223px;
font-family:MS Shell Dlg;z-index:25">';

$query = "SELECT `Price`,`HouseType` FROM `houses` WHERE Area=$AreaChoice, 
Owned = 0 ORDER BY `price` ASC";
$result = mysql_query($query, $db_handler);
while($row = mysql_fetch_assoc($result)) {
echo '<option>£'.$row['price'].' - '.$row['name'].'</option>';
}

?>

 

 

Any help is much appreciated.

You have two easy options. One is using session so u pass variables to sessions and then just call them like:

 

session_start();
$Area = $_POST['RegionComboBox'];
$StreetName = $_POST['StreetComboBox'];
$_SESSION['area'] = $Area;
$_SESSION['streetname'] = $StreetName ;
header("Location: housepurchaselist.php");

 

and in the second page:

session_start();
$area = $_SESSION['area']'
$street = $_SESSION['streetname'];

 

The second option is by modifying your header location:

$Area = ($_POST['RegionComboBox']);
$StreetName = ($_POST['StreetComboBox']);
header("Location: housepurchaselist.php?area=$area&street=$StreetName");

 

in the other page:

$area = $_GET['area']'
$street = $_GET['street'];

 

Use whichever u think is better for u. The session way is more clean in my opinion then passing a lot of variables to the url, letting also access for injections and stuff.

sorry just to add i gave you the wrong code for the query... this was the one that wasn't working:

 

 

<?
$query = "SELECT `Price`,`HouseType` FROM `soldhouses` ORDER BY `price` ASC";
$result = mysql_query($query, $db_handler);
while($row = mysql_fetch_assoc($result)) {
echo '<option>£'.$row['Price'].' - '.$row['HouseType'].'</option>';
}

?>

would i have to kill that session once the user has bought the house or only once they are logged out.. i cant work out which would be more logical

 

The session will be auto killed so dont worry about that.

 

In the last code u provided, what errors are u getting? See u have echoed <option>, shouldnt there be a <select> or u didnt include it in the code? And this code u provided has nothing to do with the previous ones (a long as i can see) so please explain it.

well that query is a list box which loads up house type and price from soldhouses, which when the user picks one and clicks the buy button

 

the session variables and that query's choice that the user had chosen will go into the database for example.

 

$area = $_SESSION['area']' = North

$street = $_SESSION['streetname']; = Old Street

 

then what ever the option in the list box is chosen (which is the query) it will all then be sent together and inserted into one table. I just need to get that query working and it will all work then.

 

 

No errors occur it just shows a list box but no values in there... it should show as an example :

 

Cottage - £50000

Mansion - £56000000

 

that kinda format.

Try making the code this way:

 

<select name="select">
<?php
$query = "SELECT Price, HouseType FROM soldhouses ORDER BY price ASC";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
echo "<option value=\"$row['Price']\">£ $row['Price'] - $row['HouseType']</option>";
?>
</select>

 

I added <select>, removed smart quotes ` from the query (as they are not neccesery) and added the "value" to the <option>. If it still doesnt work, try echoing a row outside the <option> to see if data are being passed.

Replace the echo part with:

 

echo "<option value=\"" . $row['Price'] . "\">£" . $row['Price'] . " - " . $row['HouseType'] . "</option>";

or

echo "<option value=\"{$row['Price']}\">£ {$row['Price']} - {$row['HouseType']}</option>";

 

Whichever of them u like :)

hmmm with that code, if the query is right u should have the list box filled with values. See if u have the right column and table names in the query. Also try echoing rows without the option thing, to see if values are returned.

Right on the page source it says:

 

<option value="50000">£ 50000 - Cottage</option></select>

 

 

So that means it does work. But it wont display it graphically on the browser its just blank with a white square and when its click you can see the square but no text or anything.

The select syntax should be like:

<select name="select">
  <option value="Value 1">Item 1</option>
  <option value="Value 2">Item 2</option>
</select>

 

But i guess u have it right. Have u assigned a css class or smth which may make the text white, probably not the case but just to be sure.

well i don't think its that because the box which i keep mentioning is only a very small box.. the font inside it could fit in the highlight area that it shows. But it does find cottage and 50,000 which is the only values in the database... :S very odd... all fonts are black by default on my site so its not white. very unusual indeed

<select name="Combobox3" size="2" id="Combobox3" style="position:absolute;left:343px;top:520px;width:223px;font-family:MS Shell Dlg;z-index:25">';
<select name="select">

<?php
$soldhousesquery = "SELECT Price, HouseType FROM soldhouses ORDER BY price ASC";
$result = mysql_query($soldhousesquery);
while($soldhousesrow = mysql_fetch_array($result)) {
echo "<option value=\"{$soldhousesrow['Price']}\">£ {$soldhousesrow['Price']} - {$soldhousesrow['HouseType']}</option>";
}


?>
</select>

</select>

U have two nested selects and the second one must not be there as a select needs <option> as child. Try this code:

 

<select name="Combobox3" size="2" id="Combobox3" style="position:absolute;left:343px;top:520px;width:223px;font-family:MS Shell Dlg;z-index:25">
<?php
$soldhousesquery = "SELECT Price, HouseType FROM soldhouses ORDER BY price ASC";
$result = @mysql_query($soldhousesquery) or die(mysql_error());
while($soldhousesrow = mysql_fetch_array($result)) {
echo "<option value=\"{$soldhousesrow['Price']}\">£ {$soldhousesrow['Price']} - {$soldhousesrow['HouseType']}</option>";
}
?>
</select>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.