www.webdeveloper.com
Results 1 to 2 of 2

Thread: [RESOLVED] session variable problem

  1. #1
    Join Date
    May 2009
    Posts
    10

    resolved [RESOLVED] session variable problem

    Hi all,

    I wonder if anyone can explain to me why my code doesn't work and how I can correct it. I've been working on it for hours and I'm at a complete
    loss.

    I have a page dbsearch.php which, amongst other bits of php and javascript contains the following to output the results of the database query everything works fine. When I add an echo to show me the $_SESSION['sql'] variable it gives me the correct SQL query.

    PHP Code:
    <?php
    if ($result && $x 1)
        {
    print 
    "<table>\n";
    print 
    "<td><br><p>There are $x stores that match your criteria<br>Please select one of the following results:\n";
    print 
    "Please select a store from the drop-down box or click on \"Show All\"\n";
    print 
    "<tr><td><select name=\"results\" onChange=\"dropDown()\"> \n";
        print 
    "<option value=no>Please select a store...";
        while (
    $rowmysql_fetch_assoc($result))
            {
            
    $number $row['store_num'];
            
    $name $row['name'];
            print 
    "<option value=$number>$number$name \n";
            }

    print 
    "</select> or ";
    print 
    "&nbsp <input type=\"button\" value=\"Show All\" onClick=\"showAllResults()\" id=\"showall\"></p>";
    print 
    "</table>";
        }


    // $x is simply number of rows returned.
    if ($x == 0)
        {
        echo 
    "Sorry. There were no results that matched your query";
        }

    elseif (
    $result)
        {
        while (
    $row mysql_fetch_assoc($result))
            {
            
    $number $row['store_num'];
            
    $name $row['name'];
            echo 
    "There was only one result: " .$number .$name ."<br>";
            print 
    "<input type=hidden name=store id=hidden value=$number><br>";
            print 
    "<input type=radio id=Address value=address name=showme checked=true>Full Address<br><input type=button value=submit onclick=part2()>";
            }
        }
    $_SESSION['sql'] = $sql;

    ?>
    The below block of code is then called from the button to append the results of showall.php to the same page.

    When I run the above page, and then point my browser to showall.php - it executes fine, the data that I expect is echoed to the screen i.e. the sesion variable is recognised... However, when I call showall.php through the javascript function showAllResults(), it doesn't work.

    I tested the variable using within the showall.php script with (!isset($_SESSION['sql'])) statment and only when called via the javascript function does the session variable come back as not set:

    The showall.php function is called as below.

    PHP Code:
    function showAllResults(){

        
    script document.createElement('script');
        
    script.src "http://myhost.com/showall.php"
        
    document.getElementsByTagName("head")[0].appendChild(script);


    Can anyone explain what's wrong and what I need to do to make this work?

    If you need to see any more of the code just let me know.

  2. #2
    Join Date
    May 2009
    Posts
    10
    i worked around the problem using javascript and css to hide the output I didn't want to appear until after the button was pressed.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles