Solved

mysql insert statement with data in certain fields

Posted on 2003-11-28
5
3,850 Views
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!

Chris



0
Comment
Question by:ChrisAndrews
  • 3
5 Comments
 
LVL 5

Accepted Solution

by:
arjanh earned 100 total points
Comment Utility
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]')");
0
 

Author Comment

by:ChrisAndrews
Comment Utility

Thank you !

Chris
0
 
LVL 1

Expert Comment

by:Hardaway
Comment Utility
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.
0
 

Author Comment

by:ChrisAndrews
Comment Utility

Thank you Arjanh, they are :)

Chris
0
 

Author Comment

by:ChrisAndrews
Comment Utility

oopps, I mean Thank you Hardaway of course -
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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 count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now