Page 1 of 1

How to reset dropdowns

Posted: Thu Dec 30, 2010 11:56 pm
by Badar
Hi,
I have 5 dropdowns, each one dependent on the previous one (except the first one obviously). These drop downs are named as City, Area, Block, Street, Label.
City drop down's code is as follows

Code: Select all

<form name="theForm" method="get">

    <!-- city SELECTION -->
    
    <select name="city" onChange="autoSubmit();">
        <option value="null">Select City.....</option>
                    //the code to fetch data from mysql goes here 

//Where autoSubmit() is defined as

<script language="JavaScript">

function autoSubmit()
{
    var formObject = document.forms['theForm'];
    formObject.submit();
}

</script>

Now comes my problem.
The following code runs fine on my localhost (i am using wampserver 2.0i) or even any other localhost (that means it doesn't seem to have common mistakes like session isn't started etc).

Code: Select all

if($city != null && is_numeric($city) && $area != null && is_numeric($area) && $block != null && is_numeric($block) && $street != null && is_numeric($street) && $label != null && is_numeric($label))
{

$_SESSION['city'] = $city;
$_SESSION['area'] = $area;
$_SESSION['block'] = $block;
$_SESSION['street'] = $street;
$_SESSION['label'] = $label;

require("map.php");
$city = $area = $block = $street = $label = 0;  //RESETS THE DROPDOWNS SO THAT AFTER THIS LOOP THERE IS ONLY CITY DROPDOWN VISIBLE WITH DEFAULT NULL VALUE
}
else
{
//some code here
}
map.php requires another file to generate xml file.
This code runs smooth on my localhost. After making complete selection till label, it shows the marker on google map. But when i uploaded this on my domain, it doesn't execute require("map.php") properly and just resets the dropdowns(i mean no map or marker is visible).
That means session variable aren't passed to map.php or other file (required in map.php).
I am stuck in it for two days and couldn't find a solution. Any help would be highly appreciated. I Think i have decribed everything properly. If still some questions, feel free to ask.
Regards

Re: How to reset dropdowns

Posted: Fri Dec 31, 2010 12:03 am
by josh
Badar wrote:The following code runs fine on my localhost (i am using wampserver 2.0i) or even any other localhost (that means it doesn't seem to have common mistakes like session isn't started etc).
no it doesn't mean that, it probably means that is in fact your mistake (for example session auto start may be enabled on the servers where you observed it working).

Re: How to reset dropdowns

Posted: Fri Dec 31, 2010 12:15 am
by Badar
josh wrote: session auto start may be enabled on the servers where you observed it working).
But i have put session_start(); at the start of both files, from where and to whom i want to send these variables. Moreover, if i delete the line

Code: Select all

$city = $area = $block = $street = $label = 0;
then the code works fine on my domain too. And session auto start is off both on domain and localhost

Re: How to reset dropdowns

Posted: Fri Dec 31, 2010 1:16 am
by Badar
Most probably there is something different in php.ini file of my domain than the one on my localhost. But i can't figure out what it could be. It's urgent so can somebody guide me through this problem.
Note:- I can't change php.ini file on my domain. So what are the possible alternatives if it really is the problem of some settings in php.ini
Here are the differences of session settings that i found between my localhost and domain
........................................................Domain..................................Localhost
..............................................local.................master...........local....................master
session.gc-divisor.........................100...................100..............1000....................1000
session.hash_bits_per_character..........4.....................4.................5........................5
session.use_only_cookies.................off...................off...............on.......................on
I don't know, whether these differences matter or no but i posted for reference just in case

Re: How to reset dropdowns

Posted: Fri Dec 31, 2010 4:08 am
by josh
Run this script:

Code: Select all

<?php
session_start();
$_SESSION['foo']++;
var_dump($_SESSION);
If sessions work, it will error the first time, and then count on each subsequent request.
If there is a session issue, it will error on every reload.

Divide and conquer. This will rule in/rule out your theory. :-)

The php.ini differences you posted should not matter. When it garbage collects, it checks the last modified date before trashing an active session. Those settings really only matter for performance. (see session.gc_maxlifetime, that would be the culprit if anything.)

Re: How to reset dropdowns

Posted: Fri Dec 31, 2010 4:42 am
by Badar
josh wrote:see session.gc_maxlifetime, that would be the culprit if anything.
nah. session.gc_maxlifetime has both values set to 1440 both on domain and localhost
josh wrote:Run this script:

Code: Select all

<?php
session_start();
$_SESSION['foo']++;
var_dump($_SESSION);
If sessions work, it will error the first time, and then count on each subsequent request.
If there is a session issue, it will error on every reload.
I added the lines

Code: Select all

$_SESSION['foo']++;
var_dump($_SESSION);
at the beginning of my code just after session_start(); in my local and web file. As earlier, the code runs smooth till the final selection. but as soon as final selection is made (i mean values are selected from all five boxes), my web page just resets the dropdowns without sending the session variables may be. No error is shown on both my web page and the one on localhost. here is the result of adding above lines in the code
on localhost:- array(5) { ["foo"]=> int(10) ["city"]=> string(1) "3" ["area"]=> string(3) "164" ["block"]=> string(4) "1226" ["street"]=> string(4) "4076" }
on web page:-array(6) { ["city"]=> &string(1) "3" ["area"]=> &string(3) "164" ["block"]=> &string(4) "1226" ["street"]=> &string(4) "4076" ["label"]=> &int(0) ["foo"]=> &int(7) }
i can see difference between the two, though same selection was made on both files so it should have shown the same result. But it is not showing same results. so what to do now? i don't understand, what both lines mean

Re: How to reset dropdowns

Posted: Fri Dec 31, 2010 4:51 am
by Badar
i forgot to mention the results on opening local and web pages
on localhost:- array(6) { ["city"]=> &int(0) ["area"]=> &int(0) ["block"]=> &int(0) ["street"]=> &int(0) ["label"]=> &int(0) ["foo"]=> &int(8) }
on web page:-array(6) { ["foo"]=> int(12) ["city"]=> string(1) "3" ["area"]=> string(3) "164" ["block"]=> string(4) "1226" ["street"]=> string(4) "4076" ["label"]=> string(3) "399" }
and when i logged in after restarting my computer and opened both pages, following was the result
on localhost:- array(6) { ["foo"]=> int(2) ["city"]=> string(1) "3" ["area"]=> string(3) "176" ["block"]=> string(4) "1239" ["street"]=> string(4) "4160" ["label"]=> string(6) "159474" }
on web page:-array(1) { ["foo"]=> int(1) }
After analyzing the second set of results, i guess as i am not destroying session that's why localhost is showing previous selections even after restarting the pc. But now previous result of web page matches with local page after restarting.
Why is this so?

Re: How to reset dropdowns

Posted: Fri Dec 31, 2010 4:34 pm
by josh
So were you able to rule out sessions not working then? I was asking you to run just the code I sent.. (with session_start() of course). Do sessions work on all servers or not?

Re: How to reset dropdowns

Posted: Sun Jan 02, 2011 10:58 pm
by Badar
josh wrote:So were you able to rule out sessions not working then?
First of all sorry for late reply. I have no facility of internet in my home and as it was a weekend, i didn't come to my office.

Sessions are definitely working on all servers. Here are the results of your code for both servers
web server:-array(1) { ["foo"]=> int(1) }
local server:- array(1) { ["foo"]=> int(2) }
i would like to show you my loops

Code: Select all

if($city != null && is_numeric($city))
{

if($city != null && is_numeric($city) && $area != null && is_numeric($area))
{

if($city != null && is_numeric($city) && $area != null && is_numeric($area) && $block != null && is_numeric($block))
{

if($city != null && is_numeric($city) && $area != null && is_numeric($area) && $block != null && is_numeric($block) && $street != null && is_numeric($street))
{

if($city != null && is_numeric($city) && $area != null && is_numeric($area) && $block != null && is_numeric($block) && $street != null && is_numeric($street) && $label != null && is_numeric($label))
{

$_SESSION['city'] = $city;
$_SESSION['area'] = $area;
$_SESSION['block'] = $block;
$_SESSION['street'] = $street;
$_SESSION['label'] = $label;

require("map.php");


$city = $area = $block = $street = $label = 0;

}

else
{
$_SESSION['city'] = $city;
$_SESSION['area'] = $area;
$_SESSION['block'] = $block;
$_SESSION['street'] = $street;

require("streetaddmap.php");
}
}
else
{
$_SESSION['city'] = $city;
$_SESSION['area'] = $area;
$_SESSION['block'] = $block;

require("blockaddmap.php");
}
}
else
{
$_SESSION['city'] = $city;
$_SESSION['area'] = $area;

require("areaaddmap.php");
}
//.
//.
//.
//code for rest of the loops goes here.
my only problem is that until i put the line $city = $area = $block = $street = $label = 0; to reset my dropdowns, everything is ok on all servers, i.e. sessions are passed without no worries. but as soon as i reset the dropdowns using above line, the resulted map.php returns no result (only on my web server, but still woks fine on local servers). Here, what i could guess is, while executing inner most loop, php 1st resets the variables and then send it to map.php (though the line $city = $area = $block = $street = $label = 0; is written after "require" function). If this is the case then how can i avoid resetting variables before requiring map.php.
Note:- While passing variables in all outer loops, sessions are passed successfully both on local and web servers.(as i don't reset variables in other loops)