Jump to content
Larry Ullman's Book Forums
Sign in to follow this  

Greeting And A Question Of Inserting Datetime Function Into Prepare Statement

Recommended Posts

Hello there,


It's my first time asking question here, so I want to introduce myself a little bit. I was a graphic designer and 3D artist and I have never done any website except using iWeb. The company I work for needs to rebuild its website which has roughly four thousand products in the database. The website was built by hosting company using a open source CMS called OScommerce. My given project was to create a independent website using php and mysql that can be easily modified to suit the need when time is  changing. 

When I receive the project around beginning of this year, I knew nothing about php and mysql so I went to amazon to buy 2 books. One was "PHP Solutions Dynamic Web Design Made Easy" and other one "Modern Javascript". I studied through both books. The PHP Solution is a good book, but not for absolute beginner. The way it organizes its content, mixing basic and advance concerts and methods together into one book keeps new learner confused and frustrated. So I wasn't really fully understand the material I have learned. As comparison, Modern Javascript is much clear to me and easy to learn. After finished Modern Javascript, I found Mr. Larry also wrote other php books, so I decided to pick up PHP and MySQL for Dynamic from Amazon. As I studied through (followed all examples), I found this book really helped me clear up the concert that I wasn't really clear of. So ends up, I purchased all php book from Larry and finished all of them. 


Now back to the question, I run into problem to insert timestamp into prepare statement, after some goolge search, there is answer in stackoverflowhttp://stackoverflow.com/questions/14096220/datetimes-now-function-does-not-work-with-pdo-mysql-prepared-statements


I change my script according to it, but it returns an error: mysqli_stmt_bind_param(): Number of elements in type definition string doesn't match number of bind variables. I have no idea now, can anyone show me the right way to this please.  Thanks.




           // query for products table
           $query = 'INSERT INTO products (product_sku, product_name, product_size, 
                     product_color, product_packaging, product_desc, created_on, new_arrival, feature, publish)
                     VALUES (?,?,?,?,?,?,NOW(),?,?,?)';
           $stmt = mysqli_prepare($dbc, $query);
           mysqli_stmt_bind_param($stmt,'ssssissiii', $sku,$name,$size,$color,
                   $packaging,$desc, $new_arrival,$feature,$publish );









Share this post

Link to post
Share on other sites

You have only nine question marks in your query and nine variables in your mysqli_stmt_bind_param function call, but your "ssssissiii" string is ten characters long.

As such, there's a mismatch in the number of items and an error is occurring accordingly.


Also, glad you like the books and have learned a lot from them.

Good luck with your project.

  • Upvote 1

Share this post

Link to post
Share on other sites

Hi, HartleySan. The code is working now :)  thank you very much for helping out. 


I have question following about inserting multiple product images into image table and get multiple image_id using mysqli_insert_id. Should I ask in this thread or open a new one specific for it?

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...