Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Beginning PHP 5.3
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 25th, 2011, 01:27 AM
Authorized User
Points: 216, Level: 4
Points: 216, Level: 4 Points: 216, Level: 4 Points: 216, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2011
Location: USA, OHIO
Posts: 51
Thanks: 9
Thanked 0 Times in 0 Posts
Send a message via MSN to nawar youssef
Default please I need help here ....insert() function

hello everbody
I got an error like this :
Code:
Query Failed / insert() function: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
and I am using the same code but I didn't understand what does the error mean, where i have to fix or how to ????
this is my function
PHP Code:
 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() );
             }
          }
    } 
I am using $member instead of $Member, is not a mistake.
and if you need to see all my member class here it is :

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() );
             }
          }
    }
    
?>
thank you so much, I know its hard to read other people's codes.
Reply With Quote
  #2 (permalink)  
Old October 25th, 2011, 03:41 AM
Friend of Wrox
Points: 639, Level: 9
Points: 639, Level: 9 Points: 639, Level: 9 Points: 639, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Location: North East UK
Posts: 119
Thanks: 0
Thanked 23 Times in 23 Posts
Default

Greetings,

I am guessing here but your problem could be due to this:
Code:
:password(:password),
try changing it to:
Code:
password(:password),
that way it'll use the PASSWORD function to encrypt the supplied password.
Reply With Quote
  #3 (permalink)  
Old October 25th, 2011, 10:05 PM
Authorized User
Points: 216, Level: 4
Points: 216, Level: 4 Points: 216, Level: 4 Points: 216, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2011
Location: USA, OHIO
Posts: 51
Thanks: 9
Thanked 0 Times in 0 Posts
Send a message via MSN to nawar youssef
Default thanks, but still

thank you I change it and it was a mistak but I had another error its the same code number but it tells me this time that the parameter was not found:
Code:
SQLSTATE[HY093]:Invalid parameter number: parameter was not defined
I hope you know what does that mean, and do you know if there any php validator like html and css, it will vary useful for me.
thank you
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bulk Insert Function jdegrate Visual Basic 2008 Essentials 3 March 18th, 2009 05:56 PM
send variable in function to another function schoolBoy Javascript How-To 6 March 3rd, 2007 08:16 AM
How to call javascript function from VB function vinod_yadav1919 VB How-To 0 February 13th, 2006 05:03 AM
trigger to insert current date on insert kev_79 SQL Server 2000 3 January 23rd, 2006 04:58 PM
retreive function/Line from macro or function? MikoMax J2EE 0 April 1st, 2004 03:42 AM



All times are GMT -4. The time now is 10:22 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.