Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Beginning PHP 5.3
|
BOOK: Beginning PHP 5.3
This is the forum to discuss the Wrox book Beginning PHP 5.3 by Matt Doyle; ISBN: 978-0-470-41396-8
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP 5.3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 26th, 2011, 10:12 PM
Authorized User
 
Join Date: Jun 2011
Posts: 51
Thanks: 9
Thanked 0 Times in 0 Posts
Send a message via MSN to nawar youssef
Default help in chapter 14 please

I had an error here I correct it, then another one happes but this time it says
Code:
SQLSTATE[HY093]:Invalid parameter number: parameter was not defined
PHP Code:
 <?php  

    
require_once "dataObject.class.php"

     
    class 
member extends dataObject 
        protected 
$data = array(                                                                   
            
"id" => ""
            
"username" => ""
            
"password" => ""
            
"firstName" => ""
            
"lastName" => ""
            
"joinDate" => ""
            
"gender" => ""
            
"favoriteGenre" => ""
            
"emailAddress" => ""
            
"otherInterests" => "" 
        
); 
         
        protected 
$_genres = array (                                                                
            
"herror" => "Herror"
            
"thriller" => "Thriller"
            
"romance" => "Romance"
            
"sciFi" => "Sci-Fi"
            
"nonFiction" => "Non-Finction"
            
"crime" => "Crime" 
        
); 
         
        public static function 
getMembers($startRow$numRows$order$interest="") {             
            
$conn parent::connect(); 
            
$interestFound $interest " WHERE otherInterests LIKE :interest " ""
            
$sql "SELECT SQL_CALC_FOUND_ROWS * FROM " TBL_MEMBERS "  
                    
$interestsFound ORDER BY $order LIMIT :startRow, :numRows"
             
            try { 
                
$st $conn->prepare($sql); 
                
$st->bindValue(":startRow"$startRowPDO::PARAM_INT); 
                
$st->bindValue(":numRows"$numRowsPDO::PARAM_INT); 
                if (
$interest$st->bindValue(":interest""%$interest%"PDO::PARAM_STR); 
                
$st->execute(); 
             
            
$members = array(); 
            foreach (
$st->fetchAll() as $row) { 
                
$members[] = new member($row); 
            } 
             
            
$st $conn->query("SELECT found_rows() AS totalRows"); 
            
$row $st->fetch(); 
            
parent::disconnect($conn); 
             
            return array( 
$members$row["totalRows"] ); 
             
            }catch (
PDOException $e) { 
                
parent::disconnect($conn); 
                die( 
"Query Failed! / getMembers() function : " $e->getmessage() ); 
            } 
        } 
         
        public static function 
getMember$id) {                                                 
            
$conn parent::connect(); 
            
$sql "SELECT * FROM " TBL_MEMBERS " WHERE id = :id"
            try { 
                    
$st $conn->prepare($sql); 
                    
$st->bindValue(":id"$idPDO::PARAM_INT); 
                    
$st->execute(); 
                    
$row $st->fetch(); 
                    
parent::disconnect($conn); 
                    if (
$row)  
                        return new 
member($row); 
                }catch (
PDOException $e) { 
                    
parent::disconnect($conn); 
                    die(
"Query Faild! / getMember() function: " $e->getmessage() ); 
                } 
            } 
             
            public function 
getGenderString() {                                                     
                return  (
$this->data["gender"] == "f") ? "Female" "Male" 
            } 
             
            public function 
getFavoriteGenreString() {                                             
                return (
$this->_genres[$this->data["favoriteGenre"]] ); 
            } 
         
        public static function 
getByUsername($username){                                     
            
$conn parent::connect(); 
            
$sql"Select * from " TBL_MEMBERS " where username = :username"
             
            try { 
                
$st $conn->prepare($sql); 
                
$st->bindValue(":username"$usernamePDO::PARAM_STR); 
                
$st->execute(); 
                
$row $st->fetch(); 
                
parent::disconnect($conn); 
                if (
$row) return new member($row); 
            }catch (
PDOException $e){ 
                
parent::disconnect($conn); 
                die (
"Query Failed /getByUsername() function : " $e->getmessage() ); 
            } 
             
        } 
         
        public static function 
getByEmailAddress($emailAddress){ 
            
$conn parent::connect(); 
            
$sql "select * from " TBL_MEMBERS " where emailAddress = :emailAddress"
             
            try{ 
            
$st $conn->prepare($sql); 
            
$st->bindValue(":emailAddress"$emailAddressPDO::PARAM_STR); 
            
$st->execute(); 
            
$row $st->fetch(); 
            
parent::disconnect($conn); 
            if(
$row) return new member($row); 
            }catch (
PDOException $e){ 
                echo 
"Query Faild /getByEmailAddress() function: " $e->getmessage(); 
            } 
        } 
         
        public function 
getGenres() { 
            return 
$this->_genres
        } 
         
        public function 
insert(){ 
            
$conn parent::connect(); 
            
$sql "insert into " TBL_MEMBERS " (  
                username,  
                password,  
                firstName,  
                lastName,  
                joinDate, 
                gender,  
                favoriteGenre,  
                eamilAddress,  
                otherInterests                 
            ) values (  
                :username,  
                password(:password),  
                :firstName,  
                :lastName,  
                :joinDate, 
                :gender,  
                :favoriteGenre,  
                :emailAddress,  
                :otherInterests 
            ) "

             
            try { 
                
$st $conn->prepare($sql); 
                
$st->bindValue(":username"$this->data["username"], PDO::PARAM_STR); 
                
$st->bindValue(":password"$this->data["password"], PDO::PARAM_STR); 
                
$st->bindValue(":firstName"$this->data["firstName"], PDO::PARAM_STR); 
                
$st->bindValue(":lastName"$this->data["lastName"], PDO::PARAM_STR); 
                
$st->bindValue(":joinDate"$this->data["joinDate"], PDO::PARAM_STR); 
                
$st->bindValue(":gender"$this->data["gender"], PDO::PARAM_STR); 
                
$st->bindValue(":favoriteGenre"$this->data["favoriteGenre"], PDO::PARAM_STR); 
                
$st->bindValue(":emailAddress"$this->data["emailAddress"], PDO::PARAM_STR); 
                
$st->bindValue(":otherInrerests"$this->data["otherInterests"], PDO::PARAM_STR); 
                
$st->execute(); 
                
parent::disconnect($conn); 
            }catch (
PDOException $e){ 
                
parent::disconnect($conn); 
                die(
"Query Failed / insert() function: " .$e->getmessage() ); 
             } 
          } 
    }
?>
 
Old October 27th, 2011, 02:46 AM
Friend of Wrox
 
Join Date: May 2011
Posts: 125
Thanks: 0
Thanked 24 Times in 24 Posts
Default

Greetings,

As there is no mention of :number in the code provided above the problem is in another file.

I have no idea which one but it should be easy to do a search within files looking for ":number" and then moving on from there once you know where to look.
 
Old October 27th, 2011, 08:34 PM
Authorized User
 
Join Date: Jun 2011
Posts: 51
Thanks: 9
Thanked 0 Times in 0 Posts
Send a message via MSN to nawar youssef
Default I have nothing calles number in my script.

I have nothing calles number in my whole script and all files, do I should have it?
I thing the error message means that the number of the parameters are not match or something, but I looked at that and did not work. a lot of people on the net have similar problem but I could not find any solution.
do you have another Idea?
thank you
 
Old October 27th, 2011, 11:36 PM
Authorized User
 
Join Date: Jun 2011
Posts: 51
Thanks: 9
Thanked 0 Times in 0 Posts
Send a message via MSN to nawar youssef
Default ohh MAN I got it, its a stupid mistake

I am soryy I bothered u, it a stupid mistake at the emailAddress I had wrote it eamilAddress, but I don't why I did not got the error for this at the beginning then the error has changed and say something about 'eamilAddress' so I knew it





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 14, first 'Try It Out' alharlow BOOK: Beginning ASP.NET 4 : in C# and VB 5 March 18th, 2011 05:00 AM
chapter 14 vthunder70 BOOK: Beginning ASP.NET 2.0 and Databases 2 October 3rd, 2007 02:11 PM
Chapter 14 example pkumar@ech BOOK: Professional Jakarta Struts 0 November 15th, 2006 09:10 AM
Chapter 14 JonG BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 1 March 21st, 2006 10:04 PM
Chapter 14 Mike Smith BOOK: Professional C#, 2nd and 3rd Editions 2 January 4th, 2004 05:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.