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

    Join Date
    Jan 2013
    Posts
    87
    Rep Power
    2

    I keep getting an error which I dont understand


    I keep getting this error which I shouldn't be because the other functions work just fine:

    Fatal error: Call to undefined function prepare() in


    Here is my code:

    PHP Code:
    <?php

    function insert_album($directory_path$album_name$db){


            
    $sql "INSERT INTO Group_1(id, dir_path, a_name) VALUES(:id, :directory_path, :album_name)";    

            
    $q $db -> prepare($sql);    
            
            
    $q -> execute(array(
            
                
    ':id' => $id,
                    
                
    ':directory_path' => $directory_path,
        
                
    ':album_name'  => $album_name
                    
                
    ));
            
            return 
    true;
            
        
            
    $db null;
        
    }



    function 
    insert_image_info($id$image_path$name$desc$db){


            try{
                
                
    $sql "INSERT INTO Group_2(id, image_path, image_name, image_description) VALUES(:id, :image_path, :name, :desc)";    

            
    $q $db -> prepare($sql);    
            
            
    $q -> execute(array(
            
                
    ':id' => $id,
                
                
    ':image_path' => $image_path,
                    
                
    ':name' => $name,
        
                
    ':desc'  => $desc
                    
                
    ));
                
            }catch(
    PDOException $e){
                
                echo 
    $e->getMessage();
                
            }
                
                
                
    print_r($q->errorInfo());
                
                
                return 
    TRUE;
            
        
            
    $db null;
        
    }


    function 
    loop($db){
        
        
    $sql "SELECT * FROM `Group_1`";
                
        
    $q $db->prepare($sql);
                
        echo 
    '<p>Select Album to Upload to:<br /><br /><select name="select">';
                
        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 />';
                
                
        }
        

        
    $db null;

    }


    function 
    rename_album_setup($db){
        
        
    $sql "SELECT * FROM `Group_1`";
                
        
    $q $db->prepare($sql);
                
        echo 
    '<p>Select Album to Rename:<br /><br /><select name="rename_album"><option value="">Select One...</option>';
                
        if(
    $q->execute()){
                    
                    
            while(
    $row $q->fetch(PDO::FETCH_ASSOC)){
                    
                                            
                
    $a_name $row['a_name'];
                        
                            
                echo 
    '<option value="'.$a_name.'">'.$a_name.'</option>';
                        
                        
            }
                
                
                    echo 
    '</select><br /><br />';
                
                
        }
        

        
    $db null;

    }

    [
    COLOR=Red][B]// this one
    function rename_album($newname$db){
        
        
        
        try{
                    
            
    $sql "UPDATE Group_1 SET a_name = :newname";
        
            
    $q prepare($sql);
            
            if(
    $q->execute(array(':newname' => $newname))){
                
                return 
    true;
                
            }else{
                
                return 
    false;
                
            }    
            
        }catch(
    PDOException $e){
            
            echo 
    $e->getMessage();
            
        }
        
        
    print_r($q->errorInfo());
        
    }[/
    B][/COLOR]


    function 
    db_insert_once($a_name$album_name$db){
            
        
    $sql "SELECT * FROM `Group_1`";
                
        
    $q $db->prepare($sql);
        
                
        if(
    $q->execute()){
                    
                    
            while(
    $row $q->fetch(PDO::FETCH_ASSOC)){
                        
                
    $album $row['dir_path'];
                
                
                if(
    $album == $album_name){
                        
                    return 
    true;
                    
                }else{
                            
                    return 
    false;                        
                    
                }
                        
            }    
                
        }
        
        
    $db null;
        
    }

    ?>]

    and my connect file:

    PHP Code:
    <?php

    $dbhost 
    'localhost';

    $dbname 'portfolio';

    $dbuser 'root';

    $dbpass '';
        

        
    $db = new PDO("mysql:host=$dbhost;dbname=$dbname"$dbuser$dbpass);

    include 
    'functions.php';

    ?>
  2. #2
  3. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,547
    Rep Power
    2337
    Compare one of your calls:

    php Code:
    $q = $db->prepare($sql);


    to another

    php Code:
     $q = prepare($sql);


    Which works, and which doesn't?
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    87
    Rep Power
    2
    I am really sorry for that I feel EXTREMELY stupid and upset at myself for not seeing that right now. Why is that I always miss the small details like that! I am really sorry for posting this easy fix.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,333
    Rep Power
    594
    Welcome to the club. I know of no programmer that has not done the same thing many times.

    Comments on this post

    • natturefrk agrees
    • BarryG agrees : I'm a member of that club too!
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    87
    Rep Power
    2
    now how do I get rename function(php function) to move up a directory as I am trying to implement being able to rename a directory
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    87
    Rep Power
    2
    nevermind I figured it out
  12. #7
  13. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,846
    Rep Power
    6351
    Please post the solution so people who come across this thread in the future can know as well.

    rename('file.txt', '../file.txt');

    Comments on this post

    • gw1500se agrees : Thank you for that. Nothing is more frustrating than finding your exact problem that ends with "I fixed it."
    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.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    87
    Rep Power
    2
    I just put the file with rename function in the correct directory and just update the links to that page

IMN logo majestic logo threadwatch logo seochat tools logo