#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    87
    Rep Power
    2

    PDO statement is not returning anything


    I am trying to get php and pdo to insert data into select menu based off the first choice. First off I know that there is an easier way of doing this known as ajax chained drop down menu, but I have 0 knowledge of this and it would take to long to learn how to do this. The second select menu is not showing anything I checked to see if there is any errors with my query and there was none. I checked to see if the $path variable is empty or it is not returning the right value and everything checks out. It is passing the right value and it is not empty. The $path variable is what I need to execute the PDO statement. Here is the code:


    This is where everything is being called

    PHP Code:

    <?php

    include 'init.php';

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <title>Create Album/Upload Image</title>

    <link rel="stylesheet" href="style.css" type="text/css" />

    </head>

    <body>
        
        <div class="clean_up_form">
            
            
            <form method="get" action="" />
                
                
                <?php 
                
                select_album_move
    ($db); 
                
                
    $path $_GET['select_album'];
                
                echo 
    $path;
                
                if(
    $_GET['album']){
        
                    
    select_image($path$db);
        
                }
                
                 
                
                
    ?>
            
            
            
            
            </form><br /><br /><br />
            
            
        </div>

    </body>

    This the code making the select menus and all

    PHP Code:

    <?php

    function select_album_move($db){
        
        
    $sql "SELECT * FROM `Group_1`";
                    
        
    $q $db->prepare($sql);
                            
        echo 
    '<p>Select Album where image is stored:<br /><br /><select name="select_album"><option>Choose One...</option>';
                            
        if(
    $q->execute()){
                                
                                
            while(
    $row $q->fetch(PDO::FETCH_ASSOC)){
                                
                                    
                
    $album $row['dir_path'];
                                        
                
    $a_name $row['a_name'];
                                
                                        
                echo 
    '<option value="'.$album.'">'.$a_name.'</option>';
                                    
                                    
            }
                            
                            
        echo 
    '</select><br /><br /><input type="submit" name="album" value="Select Album" />';
                            
                            
        }
        

    }



    function 
    select_image($path$db){
        
        
    $sql "SELECT * FROM `Group_2` WHERE dir_path = :$path";
                        
        
    $q $db->prepare($sql);
                            
        echo 
    '<p>Select image to move:<br /><br /><select name="select_image"><option>Choose One...</option>';
                            
        if(
    $q->execute(array(':path' => $path))){
                                
                                
            while(
    $row $q->fetch(PDO::FETCH_ASSOC)){
                                
                                    
                
    $image $row['image_name'];
                            
                
    $image_path $row['image_path'];
                                
                                        
                echo 
    '<option value="'.$image_path.'">'.$image.'</option>';
                                
                                    
            }
                            
                            
        echo 
    '</select><br /><br /><input type="submit" name="image" value="Select Image" />';
                            
                            
        }
        

    }

    ?>
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    Are you re-submitting this form? You echoed all the inputs to this function but there's no debugging within the function. There's an IF condition wrapped around the call...perhaps that's it.

    Comments on this post

    • natturefrk agrees : Thank you for your insight
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    87
    Rep Power
    2
    No I am not resubmitting the form because the submit button is not even being echoed.

    I found a flaw in my logic, but I don't know why it is doing what it is doing. For some reason in the select_image function anything after:

    PHP Code:
    <?php echo '<option value="'.$image_path.'">'.$image.'</option>'?>
    it wont do nothing. I tried again seeing if there is an error with my sql and wont even print the results. It also wont echo the submit button. I dont know if this is why the select menu is behaving the way that it is.
    Last edited by natturefrk; April 8th, 2013 at 11:35 AM. Reason: forgot something
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    Define "it won't do nothing." It stops echoing text, it redirects the page, the whole computer turns off, what happens?

    However, none of that actually matters. Look:

    PHP Code:
                if($_GET['album']){ 
         
                    
    select_image($path$db); 
         
                } 
    Is $_GET['album'] set? Based on the fact that it comes from the form on this page and you say the form isn't being submitted, I'm guessing no, it's not set. Therefore, select_image won't ever be called.

    If that's not the source of your problem, then "it won't do nothing" needs to be expanded upon.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    87
    Rep Power
    2
    Oh, I apologize for the stupidity. Yes it is being submitted because $_GET['album'] is the first submit button and it is set. To elaborate on it is not doing nothing. If you look at the function:

    PHP Code:
    function select_image($path$db){
        
        
    $sql "SELECT * FROM `Group_2` WHERE dir_path = :$path";
                        
        
    $q $db->prepare($sql);
                            
        echo 
    '<p>Select image to move:<br /><br /><select name="select_image"><option>Choose One...</option>';
                            
        if(
    $q->execute(array(':path' => $path))){
                                
                                
            while(
    $row $q->fetch(PDO::FETCH_ASSOC)){
                                
                                    
                
    $image $row['image_name'];
                            
                
    $image_path $row['image_path'];
                                
                
                        
                
    //echo "<option value=\"$image_path\">$image</option>";                                 
            
    }
                            
                            
        echo 
    '</select><br /><br /><input type="submit" name="image" value="Select Image" />';
                            
                            
        }
                    
            
    print_r($q->errorInfo());
        



    None of the code after the line that is commented out is being done, so the submit button that is being echoed is not being echoed, not even the print_r($q->errorInfo()).
    Last edited by natturefrk; April 8th, 2013 at 11:52 AM.
  10. #6
  11. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    Are you positive that's the case? Your thread title is "PDO statement is not returning anything." Now you're saying you ARE getting a return, and it's looping through some number of rows, and then not falling out of the WHILE statement? How many rows are being printed? Are those rows correct?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    87
    Rep Power
    2
    I am so sorry for the confusion and for getting you frustrated if I did. The reason I chose the title that I did is because my troubleshooting skills are at best mediocre and thought it was PDO when in fact the answer was right in front of my face that PDO is returning something. Nothing is being printed on the form but according to the query there are 3 results and the rows are correct. Here is a screenshoot of the form and mysql database:

    How do I insert a image?
    Last edited by natturefrk; April 8th, 2013 at 12:19 PM.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    87
    Rep Power
    2
    The first picture is the application and the second is the db.
    Attached Images
  16. #9
  17. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,540
    Rep Power
    2337
    Why is there a $ in your SQL statement to be prepared here?

    php Code:
    $sql = "SELECT * FROM `Group_2` WHERE dir_path = :$path";

    Comments on this post

    • natturefrk agrees : Thanks for the obvious fix, not being sarcatic just upset at myself
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  18. #10
  19. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    View the page's SOURCE, not the rendered page. You haven't demonstrated anything by showing me the select box. So I'll repeat:

    How many rows are being printed? Are those rows correct?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    87
    Rep Power
    2
    Wow I feel so stupid because the " $ " in the sql was the problem. Geeze louise. I hate when I cant see something that is staring me right in the stinkin face. THANKS TO ALL!!!!
    Last edited by natturefrk; April 8th, 2013 at 01:07 PM.
  22. #12
  23. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    That would not have had any of the effects you've stated, but I'm glad you got it working.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  24. #13
  25. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,749
    Rep Power
    9397
    I know you said you checked for errors with the query and couldn't find any, but that's exactly where the problem was. What did you do to think the query was okay?
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    87
    Rep Power
    2
    Originally Posted by requinix
    What did you do to think the query was okay?
    I used

    PHP Code:
    print_r($q->errorInfo); 
    but then again nothing was being executed after that commented line

IMN logo majestic logo threadwatch logo seochat tools logo