 |
|
| Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more. |
|
 |
|

02-16-2012, 09:59 AM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 12-03-10
Location: Essex, UK
Posts: 273
|
|
|
Php Session_Start
Hi guys, I have a wee problem I need to fix and hope someone might enlighten me on how to go about it..
I have a form on my home page like so
Code:
<form action="http://www.for-rent-nerja.com/search.php" method="get" name="search" id="search" style="background-color:#fcf5f8">
<span class="t_color3"><u><b>Property Search</b></u></span><br />
<br />
Property Ref:<br />
<input type="text" size="15" id="REF" name="REF" /><br />
Property Type:<br />
<select id="TYPE" name="TYPE" style="width: 120px">
<option value="">Any</option> <option value="apartment">Apartment</option>
<option value="villa">Villa</option>
<option value="townhouse">Townhouse</option>
</select><br />
Duration:<br />
<select id="DURATION" name="DURATION" style="width: 120px">
<option value="holiday">Holiday</option>
<option value="long term">Long Term</option>
<option value="sale">Sale</option>
</select> <br />
Town:<br />
<select id="AREA" name="AREA" style="width: 120px" onchange="onRegionChange()">
<option value="Nerja">Nerja</option>
<option value="Torrox">Torrox</option>
<option value="Frigiliana">Frigiliana</option>
<option value="Maro">Maro</option>
</select>
<div id="allForms">Area:<br />
<select id="REGION" name="REGION" style="width: 120px">
<option value="">Any</option>
<option value="Central">Central</option>
<option value="Burriana">Burriana</option>
<option value="Capistrano">Capistrano</option>
<option value="Torrecilla">Torrecilla</option>
<option value="Punta Lara">Punta Lara</option>
<option value="Parador">Parador</option>
<option value="Carabeo">Carabeo</option>
<option value="Las Minas">Las Minas</option>
<option value="La Noria">La Noria</option>
<option value="Tamango Hill">Tamango Hill</option>
<option value="Countryside">Countryside</option>
</select>
</div>
Bedrooms:<br />
<select id="BEDROOMS" name="BEDROOMS" style="width: 120px">
<option value="1 bedroom">1</option>
<option value="2 bedroom">2</option>
<option value="3 bedroom">3</option>
<option value="4 bedroom">4</option>
<option value="5 bedroom">5+</option>
</select><br />
<br />
<input name="submit" type="submit" class="text1" value="Submit" />
<input type="reset" name="Clear" value="Reset" class="text1" />
</form>
and when I search it hold the values on the search.php page like so
PHP Code:
<form action="http://www.for-rent-nerja.com/search.php" method="get" name="search" id="search" style="background-color:#fcf5f8"> <span class="t_color3"><u><b>Property Search</b></u></span><br /> <br /> Property Ref:<br /> <input type="text" size="15" id="REF" name="REF" /><br /> Property Type:<br /> <select id="TYPE" name="TYPE" style="width: 120px"> <option value=""<?php echo ($_GET['TYPE'] == '') ? ' selected="selected"' : ''; ?>>Any</option> <option value="apartment"<?php echo ($_GET['TYPE'] == 'apartment') ? ' selected="selected"' : ''; ?>>Apartment</option> <option value="villa"<?php echo ($_GET['TYPE'] == 'villa') ? ' selected="selected"' : ''; ?>>Villa</option> <option value="townhouse"<?php echo ($_GET['TYPE'] == 'townhouse') ? ' selected="selected"' : ''; ?>>Townhouse</option> </select> <br /> Duration:<br /> <select id="DURATION" name="DURATION" style="width: 120px"> <option value="holiday"<?php echo ($_GET['DURATION'] == 'holiday') ? ' selected="selected"' : ''; ?>>Holiday</option> <option value="long term"<?php echo ($_GET['DURATION'] == 'long term') ? ' selected="selected"' : ''; ?>>Long Term</option> <option value="sale"<?php echo ($_GET['DURATION'] == 'sale') ? ' selected="selected"' : ''; ?>>Sale</option> </select> <br /> Town:<br /> <select id="AREA" name="AREA" style="width: 120px" onchange="onRegionChange()"> <option value="Nerja"<?php echo ($_GET['AREA'] == 'Nerja') ? ' selected="selected"' : ''; ?>>Nerja</option> <option value="Torrox"<?php echo ($_GET['AREA'] == 'Torrox') ? ' selected="selected"' : ''; ?>>Torrox</option> <option value="Frigiliana"<?php echo ($_GET['AREA'] == 'Frigiliana') ? ' selected="selected"' : ''; ?>>Frigiliana</option> <option value="Maro"<?php echo ($_GET['AREA'] == 'Maro') ? ' selected="selected"' : ''; ?>>Maro</option> </select> <div id="allForms">Area:<br /> <select id="REGION" name="REGION" style="width: 120px"> <option value=""<?php echo ($_GET['REGION'] == '') ? ' selected="selected"' : ''; ?>>Any</option> <option value="Central"<?php echo ($_GET['REGION'] == 'Central') ? ' selected="selected"' : ''; ?>>Central</option> <option value="Burriana"<?php echo ($_GET['REGION'] == 'Burriana') ? ' selected="selected"' : ''; ?>>Burriana</option> <option value="Capistrano"<?php echo ($_GET['REGION'] == 'Capistrano') ? ' selected="selected"' : ''; ?>>Capistrano</option> <option value="Torrecilla"<?php echo ($_GET['REGION'] == 'Torrecilla') ? ' selected="selected"' : ''; ?>>Torrecilla</option> <option value="Punta Lara"<?php echo ($_GET['REGION'] == 'Punta Lara') ? ' selected="selected"' : ''; ?>>Punta Lara</option> <option value="Parador"<?php echo ($_GET['REGION'] == 'Parador') ? ' selected="selected"' : ''; ?>>Parador</option> <option value="Carabeo"<?php echo ($_GET['REGION'] == 'Carabeo') ? ' selected="selected"' : ''; ?>>Carabeo</option> <option value="Las Minas"<?php echo ($_GET['REGION'] == 'Las Minas') ? ' selected="selected"' : ''; ?>>Las Minas</option> <option value="La Noria"<?php echo ($_GET['REGION'] == 'La Noria') ? ' selected="selected"' : ''; ?>>La Noria</option> <option value="Tamango Hill"<?php echo ($_GET['REGION'] == 'Tamango Hill') ? ' selected="selected"' : ''; ?>>Tamango Hill</option> <option value="Countryside"<?php echo ($_GET['REGION'] == 'Countryside') ? ' selected="selected"' : ''; ?>>Countryside</option> </select> </div> Bedrooms:<br /> <select id="BEDROOMS" name="BEDROOMS" style="width: 120px"> <option value="1 bedroom"<?php echo ($_GET['BEDROOMS'] == '1 bedroom') ? ' selected="selected"' : ''; ?>>1</option> <option value="2 bedroom"<?php echo ($_GET['BEDROOMS'] == '2 bedroom') ? ' selected="selected"' : ''; ?>>2</option> <option value="3 bedroom"<?php echo ($_GET['BEDROOMS'] == '3 bedroom') ? ' selected="selected"' : ''; ?>>3</option> <option value="4 bedroom"<?php echo ($_GET['BEDROOMS'] == '4 bedroom') ? ' selected="selected"' : ''; ?>>4</option> <option value="5 bedroom"<?php echo ($_GET['BEDROOMS'] == '5 bedroom') ? ' selected="selected"' : ''; ?>>5+</option> </select> <br /> <br /> <input name="submit" type="submit" class="text1" value= "Submit" /> <input type="reset" name="Clear" value="Reset" class= "text1" /> </form>
The problem is, when I click a result from the search page, it takes me to a php property page, for example http://www.for-rent-nerja.com/property.php?REF=fr1049 but it drops all of the form fields! :/
I want to retain the fields from the search page to the property page so I've been looking at tutorials and thought that something like this would work on the search page:
PHP Code:
<?php session_start(); $_SESSION['TYPE'] = $_GET['TYPE']; $_SESSION['DURATION'] = $_GET['DURATION']; $_SESSION['AREA'] = $_GET['AREA']; $_SESSION['REGION'] = $_GET['REGION']; $_SESSION['BEDROOMS'] = $_GET['BEDROOMS'];
?>
with something like this to retrieve it on the property page:
PHP Code:
<?php
session_start(); $TYPE = $_SESSION['TYPE']; $DURATION = $_SESSION['DURATION']; $AREA = $_SESSION['AREA']; $REGION = $_SESSION['REGION']; $BEDROOMS = $_SESSION['BEDROOMS'];
?>
but that doesn't appear to be working. Can anyone shed some light on what I may be doing wrong?
|

02-16-2012, 10:28 AM
|
 |
Super Moderator
|
|
Join Date: 02-10-07
Location: Central Kentucky
Posts: 10,257
|
|
I think all you need to do is add a
PHP Code:
$_SESSION['user'] = $_GET['something'];
That restricts those variables to the user who is currently using them. I am not all that sharp on this subject so I may be wrong.
|

02-16-2012, 10:51 AM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 12-03-10
Location: Essex, UK
Posts: 273
|
|
Quote:
Originally Posted by ScriptMan
I think all you need to do is add a
PHP Code:
$_SESSION['user'] = $_GET['something'];
That restricts those variables to the user who is currently using them. I am not all that sharp on this subject so I may be wrong.
|
Hey ScriptMan, thanks for the reply mate!
I tried that but with no joy unfortunately.
Thanks for your input fella!
|

02-16-2012, 11:12 AM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 12-03-10
Location: Essex, UK
Posts: 273
|
|
Quote:
Originally Posted by sstoney200
Hey ScriptMan, thanks for the reply mate!
I tried that but with no joy unfortunately.
Thanks for your input fella! 
|
I do notice it is stringing in a session ID into the URL which is what it's supposed to do I think: http://www.for-rent-nerja.com/search...&submit=Submit
However it's still not taking the fields through to the property page.
This is what I have now on the search page:
PHP Code:
<?php session_start();
$_SESSION['user'] = $_GET['form'];
$_SESSION['TYPE'] = $_GET['TYPE'];
$_SESSION['DURATION'] = $_GET['DURATION'];
$_SESSION['AREA'] = $_GET['AREA'];
$_SESSION['REGION'] = $_GET['REGION'];
$_SESSION['BEDROOMS'] = $_GET['BEDROOMS'];
?>
and attempting to take it though to the property page:
PHP Code:
<?php
session_start();
$form = $_SESSION['user'];
$TYPE = $_SESSION['TYPE'];
$DURATION = $_SESSION['DURATION'];
$AREA = $_SESSION['AREA'];
$REGION = $_SESSION['REGION'];
$BEDROOMS = $_SESSION['BEDROOMS'];
?>
|

02-16-2012, 01:36 PM
|
 |
Super Moderator
|
|
Join Date: 02-10-07
Location: Central Kentucky
Posts: 10,257
|
|
I think your problem is in the syntax of:
PHP Code:
$_SESSION['user'] = $_GET['form'];
The user identity need to be a definite value as in this example:
PHP Code:
session_start();
$_SESSION['status'] = "owner";
You call always use the echo statement on subsequent pages to see what globals are or are not being passed.
PHP Code:
$var=$_SESSION['status'];
echo $var;
// or simpler
echo $_SESSION['status'];
|

02-16-2012, 01:59 PM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 12-03-10
Location: Essex, UK
Posts: 273
|
|
Ah maan, I thought I was getting better at php but this is getting the better of me!
And there was me thinking this was going to be really simple but it's giving me a right ole headache!
I'm gonna have to give it a rest for tonight but I'll return to have a crack at it tomo! I'm damned if it will beat me!
Thanks again for your input pal!
|

02-17-2012, 05:34 AM
|
 |
Contributing Member
|
|
Join Date: 11-30-11
Location: Orlando, FL
Posts: 220
|
|
Var_dump is your best friend when debugging PHP scripts.
|

02-17-2012, 05:49 AM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 12-03-10
Location: Essex, UK
Posts: 273
|
|
Hey RiptideTempora, thanks for adding some input dude!
I'm seeing this on top my property page now: array(0) { }
This is now what I'm using on the search page:
PHP Code:
<?php session_start(); $_SESSION['status'] = "owner"; $_SESSION['TYPE'] = $_GET['TYPE']; $_SESSION['DURATION'] = $_GET['DURATION']; $_SESSION['AREA'] = $_GET['AREA']; $_SESSION['REGION'] = $_GET['REGION']; $_SESSION['BEDROOMS'] = $_GET['BEDROOMS'];
?>
and this on the page that I want pass values to that displays array(0) { }:
PHP Code:
<?php
session_start(); var_dump($_SESSION); $owner = $_SESSION['status']; $TYPE = $_SESSION['TYPE']; $DURATION = $_SESSION['DURATION']; $AREA = $_SESSION['AREA']; $REGION = $_SESSION['REGION']; $BEDROOMS = $_SESSION['BEDROOMS'];
?>
Still can't get it to work and don't understand the output! :/ Any ideas? It's driving me loopy! lol
|

02-17-2012, 06:03 AM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 11-03-11
Location: Austria
Posts: 1,206
|
|
|
Well, the var_dump tells you that the $_SESSION array is empty, therefore the $owner = will not work because it is empty..
Test your search page, I think that there is the error.
Last edited by GMF; 02-17-2012 at 06:06 AM.
|

02-17-2012, 06:26 AM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 12-03-10
Location: Essex, UK
Posts: 273
|
|
Jeez man my laptop is going out the window shortly!
|

02-17-2012, 07:11 AM
|
 |
Super Moderator
|
|
Join Date: 02-10-07
Location: Central Kentucky
Posts: 10,257
|
|
|
My use of the double " " quotes was a syntax error on my part it should be 'owner'
|

02-17-2012, 08:03 AM
|
 |
Contributing Member
|
|
Join Date: 11-30-11
Location: Orlando, FL
Posts: 220
|
|
PHP Code:
ini_set("display_errors", "On");
error_reporting(E_ALL & ~E_NOTICE);
Add this above everything to see if there are any problems with sessions. Output already being sent, etc.
|

02-17-2012, 08:12 AM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 12-03-10
Location: Essex, UK
Posts: 273
|
|
Quote:
Originally Posted by ScriptMan
My use of the double " " quotes was a syntax error on my part it should be 'owner'
|
Cheers ScriptMan!  I've edited that but still no joy!
|

02-17-2012, 08:18 AM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 12-03-10
Location: Essex, UK
Posts: 273
|
|
Quote:
Originally Posted by RiptideTempora
PHP Code:
ini_set("display_errors", "On"); error_reporting(E_ALL & ~E_NOTICE);
Add this above everything to see if there are any problems with sessions. Output already being sent, etc.
|
It was saying cookie can't be sent because header is already sent or something like that! So I moved the php to very top of the page but that didn't help!
However much I hate saying it, I'm slowly succumbing to the thought of giving up! Frickin' pants!
|

02-17-2012, 08:26 AM
|
 |
Contributing Member
|
|
Join Date: 11-30-11
Location: Orlando, FL
Posts: 220
|
|
Quote:
Originally Posted by sstoney200
It was saying cookie can't be sent because header is already sent or something like that! So I moved the php to very top of the page but that didn't help!
However much I hate saying it, I'm slowly succumbing to the thought of giving up! Frickin' pants! 
|
Move session_start() above EVERYTHING else. It should be called before any HTML, text, or accidental whitespace from breaking PHP tags is shown to the user on every page $_SESSION is needed.
|

02-17-2012, 08:59 AM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 12-03-10
Location: Essex, UK
Posts: 273
|
|
Quote:
Originally Posted by RiptideTempora
Move session_start() above EVERYTHING else. It should be called before any HTML, text, or accidental whitespace from breaking PHP tags is shown to the user on every page $_SESSION is needed.
|
Yeah I did that mate, it's the very first thing on the page but it still don't work.
|

02-17-2012, 09:19 AM
|
 |
Super Moderator
|
|
Join Date: 02-10-07
Location: Central Kentucky
Posts: 10,257
|
|
|
Stoney
Is this a live site or something you are working on localhost? Show me your URL for the search page and the result page. VB tip do not include the www part and it will not show as a live link
To use $_GET the information must be contained in the page URL. If the results are posted to the results page then one would use $_POST['var']. $get_info['var'] is often used when retrieving data rows from a DB. All three things are completely different way to populate a variable.
|

02-17-2012, 09:42 AM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 12-03-10
Location: Essex, UK
Posts: 273
|
|
Quote:
Originally Posted by ScriptMan
Stoney
Is this a live site or something you are working on localhost? Show me your URL for the search page and the result page. VB tip do not include the www part and it will not show as a live link
To use $_GET the information must be contained in the page URL. If the results are posted to the results page then one would use $_POST['var']. $get_info['var'] is often used when retrieving data rows from a DB. All three things are completely different way to populate a variable.
|
Hey man, yeah it's a live site.
this is the search page: for-rent-nerja.com/search.php
and this is the page I want to retain the values on: for-rent-nerja.com/property.php
|

02-17-2012, 12:41 PM
|
 |
Super Moderator
|
|
Join Date: 02-10-07
Location: Central Kentucky
Posts: 10,257
|
|
|
Are you trying to repopulate the search box or do you want to use them internally somehow?
As a quick note your session is created by the search page mine was PHPSESSID=102efef40e64f22995233fe540cd8a6e and the URL contained all the data needed for extraction.
Of course clicking on the link took me right to the listing so you must be trying to repopulate the search box? Why else would you need to do anything?
Help me understand here.
|

02-17-2012, 04:10 PM
|
|
Banned
Latest Blog: None
|
|
Join Date: 05-01-06
Location: I live in the real world!
Posts: 329
|
|
ScriptMan I am reading it as if he wants to repopulate the dropdown.
Wouldn't it be
Property Type:<br />
<select id="TYPE" name="TYPE" style="width: 120px">
<option value=""<?php echo ($_SESSION['TYPE'] == '') ? ' selected="selected"' : ''; ?>>Any</option>
<option value="apartment"<?php echo ($_SESSION['TYPE'] == 'apartment') ? ' selected="selected"' : ''; ?>>Apartment</option>
<option value="villa"<?php echo ($_SESSION['TYPE'] == 'villa') ? ' selected="selected"' : ''; ?>>Villa</option>
<option value="townhouse"<?php echo ($_SESSION['TYPE'] == 'townhouse') ? ' selected="selected"' : ''; ?>>Townhouse</option>
</select>
Changing all of those $_GET's to $_SESSIONS ?
I mean afterall he is checking for values.
Smack me if I am out of line here
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 08:51 AM.
Powered by vBulletin Copyright © 2000-2013 Jelsoft Enterprises Limited.
Copyright © 2003 - 2013 Escalate Media LP
|
|
|