thefollower Posted August 25, 2007 Share Posted August 25, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66687-solved-how-do-i-pass-variables-on-a-location/ Share on other sites More sharing options...
Fadion Posted August 25, 2007 Share Posted August 25, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66687-solved-how-do-i-pass-variables-on-a-location/#findComment-334104 Share on other sites More sharing options...
thefollower Posted August 25, 2007 Author Share Posted August 25, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66687-solved-how-do-i-pass-variables-on-a-location/#findComment-334107 Share on other sites More sharing options...
thefollower Posted August 25, 2007 Author Share Posted August 25, 2007 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>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/66687-solved-how-do-i-pass-variables-on-a-location/#findComment-334115 Share on other sites More sharing options...
Fadion Posted August 25, 2007 Share Posted August 25, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66687-solved-how-do-i-pass-variables-on-a-location/#findComment-334118 Share on other sites More sharing options...
thefollower Posted August 25, 2007 Author Share Posted August 25, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66687-solved-how-do-i-pass-variables-on-a-location/#findComment-334123 Share on other sites More sharing options...
Fadion Posted August 25, 2007 Share Posted August 25, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66687-solved-how-do-i-pass-variables-on-a-location/#findComment-334144 Share on other sites More sharing options...
thefollower Posted August 25, 2007 Author Share Posted August 25, 2007 I got this: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\housepurchaselist.php on line 51 Quote Link to comment https://forums.phpfreaks.com/topic/66687-solved-how-do-i-pass-variables-on-a-location/#findComment-334149 Share on other sites More sharing options...
Fadion Posted August 25, 2007 Share Posted August 25, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66687-solved-how-do-i-pass-variables-on-a-location/#findComment-334155 Share on other sites More sharing options...
thefollower Posted August 25, 2007 Author Share Posted August 25, 2007 its kinda working but its still blank. There is a value there cos when i click in the box it shows a boarder around the value but its a tiny square in the left corner.. doesnt seem to show the words... Quote Link to comment https://forums.phpfreaks.com/topic/66687-solved-how-do-i-pass-variables-on-a-location/#findComment-334158 Share on other sites More sharing options...
Fadion Posted August 25, 2007 Share Posted August 25, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66687-solved-how-do-i-pass-variables-on-a-location/#findComment-334175 Share on other sites More sharing options...
thefollower Posted August 25, 2007 Author Share Posted August 25, 2007 Ok i will have to try tmorrow morning as its getting late. I will message ya if i cant get it fix and will update this thread tmorrow. thanks for the help for now Quote Link to comment https://forums.phpfreaks.com/topic/66687-solved-how-do-i-pass-variables-on-a-location/#findComment-334176 Share on other sites More sharing options...
thefollower Posted August 26, 2007 Author Share Posted August 26, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66687-solved-how-do-i-pass-variables-on-a-location/#findComment-334472 Share on other sites More sharing options...
thefollower Posted August 26, 2007 Author Share Posted August 26, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/66687-solved-how-do-i-pass-variables-on-a-location/#findComment-334507 Share on other sites More sharing options...
Fadion Posted August 26, 2007 Share Posted August 26, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66687-solved-how-do-i-pass-variables-on-a-location/#findComment-334509 Share on other sites More sharing options...
thefollower Posted August 26, 2007 Author Share Posted August 26, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66687-solved-how-do-i-pass-variables-on-a-location/#findComment-334510 Share on other sites More sharing options...
Fadion Posted August 26, 2007 Share Posted August 26, 2007 Ok post the code u have right now with the query stuff and the select so i'll have a look. If u have the script hosted somewhere then let me show how the select looks. Quote Link to comment https://forums.phpfreaks.com/topic/66687-solved-how-do-i-pass-variables-on-a-location/#findComment-334535 Share on other sites More sharing options...
thefollower Posted August 26, 2007 Author Share Posted August 26, 2007 <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> Quote Link to comment https://forums.phpfreaks.com/topic/66687-solved-how-do-i-pass-variables-on-a-location/#findComment-334665 Share on other sites More sharing options...
Fadion Posted August 26, 2007 Share Posted August 26, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/66687-solved-how-do-i-pass-variables-on-a-location/#findComment-334814 Share on other sites More sharing options...
thefollower Posted August 27, 2007 Author Share Posted August 27, 2007 Argh it works yay thankyou so much for you time and help ! much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/66687-solved-how-do-i-pass-variables-on-a-location/#findComment-335209 Share on other sites More sharing options...
Fadion Posted August 27, 2007 Share Posted August 27, 2007 Glad it worked . Good luck with your script. Quote Link to comment https://forums.phpfreaks.com/topic/66687-solved-how-do-i-pass-variables-on-a-location/#findComment-335244 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.