Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Member
    Join Date
    Jun 2007
    Location
    Scotts Valley, CA
    Posts
    49
    Member #
    15405
    I've had some really great experiences here in terms of finding help. Have run into another issue. Here, I'm trying to set up a search so that my customers can find images of product. I'm using dependent dropdown menus for the user to figure out what style they'd like to see. The code for the menus looks like this:
    Code:
    <?
        include ("PHP/productShotsFunctions.php");
    ?>
    <div id="text">
    <form name="seasonQuery" method="get">
        <select name="season" onchange="this.form.submit();>        
            <option selected= "selected" value="null"></option>
            <?
            getSeasons();
            ?>
        </select>
        <select name="style" onchange="this.form.submit();">
            <option value="null"></option>
            <?
            getStyles();
            ?>  
        </select>
    </form>    
    <?
        getImages();
    ?>
    </div>
    Then, here's what's on productShotsFunctions:

    PHP Code:
    <?
    function getSeasons ()
        {
        include_once (
    'PHP/mySQLConnect.php');
        
    connectToDB($username$password);
        @
    mysql_select_db('session_distributors');
        
        
    $seasonquery mysql_query ("SELECT * FROM Seasons");
        
        while(
    $row mysql_fetch_array($seasonquery))
            {        
                echo (
    "<option select= 'selected' value= $row[SeasonCode]. ($seasonquery == $row["SeasonCode"] ? " selected" "") . ">$row[Season]</option>");        
            }
         }

    function 
    getStyles()
        {
        include_once (
    'PHP/mySQLConnect.php');
        
    connectToDB($username$password);
        @
    mysql_select_db('session_distributors');
        
        
    $season $_GET["season"];
        
    $stylequery mysql_query ("SELECT * FROM Styles WHERE Season = '$season'");
        
        while(
    $row mysql_fetch_array($stylequery))
            {        
                echo (
    "<option select= 'selected' value= $row[Style]. ($seasonquery == $row["Style"] ? " selected" "") . ">$row[Name]</option>");
            }
         }
        

    function 
    getImages()
        {
        include_once (
    'PHP/mySQLConnect.php');
        
    connectToDB($username$password);
        @
    mysql_select_db('session_distributors');
        
        
    $style $_GET["style"];
        
    $stylequery mysql_query ("SELECT * FROM Images WHERE Style = '$style'");
        
        while(
    $row mysql_fetch_array($stylequery))
            {        
                echo (
    "<div id='productShot'><img src= $row[gifURL]/><div id= 'text'><a href= $row[jpgURL]>Download Image></a></div></div>");
            }
        }            
    ?>
    The mySQLConnect.php code looks like this:

    PHP Code:
    <?
    $username 
    "foobar";
    $password "foo";

    function 
    connectToDB ($username$password)
    {
    mysql_connect(localhost,$username,$password);
    }
    ?>
    I'm coming up with this error:

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'session'@'localhost' (using password: NO) in .../mySQLConnect.php on line 7

    I'm not sure where I'm losing the password, and I get the results, just also get the error message at the bottom of the page.

    The reason I posted the larger code (rather than just mySQLConnect.php), is that I've used the same connection function several times now, and have not had similar problems.

    Cheers,

    K.

  2.  

  3. #2
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    None of your functions have access to the global $username and $password variables. You'll want to add this at the beginning of the functions:
    PHP Code:
    global $username$password
    As a side note, you should be putting `localhost' in quotes.

  4. #3
    Member
    Join Date
    Jun 2007
    Location
    Scotts Valley, CA
    Posts
    49
    Member #
    15405
    Thanks, Shadowfiend.

    Have 'localhost' in quotes now, and tried setting the global variables $username and $password (the code you suggested) at the top of productShotsFunctions.php.

    Everything works (I'm able to do the search and to call up the images). However, I'm also still getting the error message.

    Am I putting the global variable code in the wrong spot?

    Cheers,

    k.

  5. #4
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Possibly? It should be at the beginning (i.e., the first line after the {) of every function that uses connectToDB.

  6. #5
    Member
    Join Date
    Jun 2007
    Location
    Scotts Valley, CA
    Posts
    49
    Member #
    15405
    Thank you, thank you, thank you!!

    I had included it at the head of the sheet, rather than within each function.

    Now I'm off to hunt down the best option for maintaining state on those dropdowns...

    Cheers,

    k.

  7. #6
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 02:33 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com