mysql insert statement with data in certain fields

Posted on 2003-11-28
Last Modified: 2008-07-03

Ok, now I have:

mysql_query("INSERT INTO user VALUES ('$cust_data[0]','$cust_data[1]','$cust_data[2]','$cust_data[3]','$cust_data[4]','$cust_data[5]')");

Which inserts data into a table with six fields.

However....  I have more than six fields in this table, so I get an error.  Each month the table will grow by one field.

How can I change this so that the data will go into the first six fields of the table, and leave the remaining fields (however many there are) empty (data to be added later), without an error?

If needed, the names of the first six fields are: number, brand, account, order date, name, status.

Thanks for any assistance you can provide.  This is the last question for this project, once I have this it will all work!


Question by:ChrisAndrews
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Accepted Solution

arjanh earned 100 total points
ID: 9840021
you can name the columns to put the data in like this:

mysql_query("INSERT INTO user (number, brand, account, order date, name, status) VALUES ('$cust_data[0]','$cust_data[1]','$cust_data[2]','$cust_data[3]','$cust_data[4]','$cust_data[5]')");

Author Comment

ID: 9840173

Thank you !


Expert Comment

ID: 9840818
Arjanh should have helped you already. I would like to remind you all "additional" fields in the coming future must be nullable field. Otherwise, you would encounter error as non-nullable fields can't contain null values.

Author Comment

ID: 9841096

Thank you Arjanh, they are :)


Author Comment

ID: 9841098

oopps, I mean Thank you Hardaway of course -

Featured Post

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question