473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

MySQL ignores INSERT queries unless I specify values for every column

I've searched through this forum as well as some other forums, no one else seems to have had this problem. maybe somebody knows what's going on:

I got fed up with my hosting service's limiting my processor power. It was taking far too long to do stuff. So I created my own server. It's a windows machine, but I put the latest versions of Apache, mysql, and php on it. All are configured basicly to defualts besides the changes I had to make so that I could actually access the server.

On to the problem. I'll use the following simple table to descirbe.

table name : tab
fields : (name, address, city, zip)

On the site that I pay to get hosted, I could write a simple php insert to the table that didn't use all the fields:
Expand|Select|Wrap|Line Numbers
  1. mysql_query("INSERT INTO tab (name, zip) VALUES ('something', 'something')"); 
This would work fine. it would insert blanks into the fields address and city.

Now on my own server, It won't even do the insert when i write it like that.

I have to write the insert as
Expand|Select|Wrap|Line Numbers
  1. mysql_query("INSERT INTO tab (name, address, city, zip) VALUES ('something', '', 'something', '')"); 
If i don't write it like that, it just ignores the insert. I know writing it the second way works, i've tested it on smaller tables I have.

Is there a setting I can change on my server that allows for the previous method? I don't really understand why it would work on one server but not another.

Any help would be appreciated. Thanks
Aug 18 '07 #1
4 1773
Atli
5,058 Expert 4TB
HI, and welcome to TSDN!

When you leave out a column in a INSERT statement, you must make sure that the column either accepts NULL values or that it has a default value. Auto Increment fields can also be left out safely.

MySQL should return an error if there is a problem with your query. Try printing the mysql_error() function if your query is unsuccessful. Like so:
Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query("Insert statement here") or die(mysql_error());
  2.  
That should show you exactly what has gone wrong with your query.
Aug 18 '07 #2
Thanks for the input :) Most of my fields are text fields. If I set them up to defualt to a blank, that will fix it? I'll do the error statement printout as well. Maybe that'll shed some light on the subject.
Aug 19 '07 #3
pbmods
5,821 Expert 4TB
Heya, Agentmanatee.

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

Changed thread title to better describe the problem (did you know that threads whose titles that do not follow the Posting Guidelines actually get FEWER responses?).
Aug 19 '07 #4
My bad, I read the read this before you post thread, didn't even see the nice little box on the side. Thank you for the help.
Aug 19 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: Westcoast Sheri | last post by:
To keep track of how many fruits my visitors buy, I use a mySQL database (2 columns: "fruit" and "quantity")....so can we make these following mySQL queries work somehow? (visitor buys 5...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
10
by: Python_it | last post by:
Python 2.4 MySQL-python.exe-1.2.0.win32-py2.4.zip How can I insert a NULL value in a table (MySQL-database). I can't set a var to NULL? Or is there a other possibility? My var must be variable...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
19
by: cover | last post by:
Is there a restriction to the number of fields you can work with in a PHP to MySQL connection? I'd used as many as 15 quite a few times and now I have a form with 34 fields and can't seem to get...
30
by: Einstein30000 | last post by:
Hi, in one of my php-scripts is the following query (with an already open db-connection): $q = "INSERT INTO main (name, img, descr, from, size, format, cat, host, link, date) VALUES ('$name',...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
1
ssnaik84
by: ssnaik84 | last post by:
Hi Guys, Last year I got a chance to work with R&D team, which was working on DB scripts conversion.. Though there is migration tool available, it converts only tables and constraints.. Rest of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.