Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default char value not working

Status
Not open for further replies.

tyrannus

MIS
Apr 6, 2006
115
US
Hi all, I am submitting a query that writes information into a table, I have two fields setup that do not allow null values, and if the data i am submitting has a null value for that field it should put the default value of N into that field. However it is not doing so and I cannot figure out why.
 
Can you post the table definition and query you are writing? Thanks.
 
table description
Code:
+-------------+-------------+------+-----+---------+----------------+
| Field       | Type        | Null | Key | Default | Extra          |
+-------------+-------------+------+-----+---------+----------------+
| description | varchar(20) |      |     |         |                |
| month       | varchar(20) |      |     |         |                |
| date        | int(3)      |      |     | 0       |                |
| stclosed    | char(1)     |      |     | N       |                |
| stopenh     | char(2)     |      |     |         |                |
| stopenm     | char(2)     |      |     |         |                |
| stclosedh   | char(2)     |      |     |         |                |
| stclosedm   | char(2)     |      |     |         |                |
| rxclosed    | char(1)     |      |     | N       |                |
| rxopenh     | char(2)     |      |     |         |                |
| rxopenm     | char(2)     |      |     |         |                |
| rxclosedh   | char(2)     |      |     |         |                |
| rxclosedm   | char(2)     |      |     |         |                |
| lognum      | int(3)      |      | PRI | NULL    | auto_increment |
+-------------+-------------+------+-----+---------+----------------+


Query
Code:
insert into timeconditions(description, month, date, stclosed, stopenh, stopenm, stclosedh, stclosedm, rxclosed, rxopenh, rxopenm, rxclosedh, rxclosedm) values('$dayx', '$monthx', '$datex', '$stclosedx', '$stopenhx', '$stopenmx', '$stclosedhx', '$stclosedmx', '$rxclosedx', '$rxopenhx', '$rxopenmx', '$rxclosedhx', '$rxclosedmx')"

It is from a php program I am writing. the thing to look at is $stclosedx and $rxclosedx. Those values go into the table fields stclosed and rxclosed. The values come from a checkbox, if the box is checked, the value is Y and that info is in the table. If the box is unchecked, its a NULL value and does not post in the table with the default value of N.
 
Have you tried the insert statement outside of PHP to see if it works? First step in troubleshooting SQL is to try your queries outside of any programming language. If it works there, try posting your question in the PHP forum. If not, let us know the error you get.
 
I know for a fact that a null value is in there and for some reason, the sql table is accepting NULL values when its not supposed to be. I have already double checked the PHP side of it.
 
I will have to defer to someone more experienced than I. I cannot see why your table would accept NULLs if it is defined correctly.
 
I don't know either, for now I will cheat and run a query that will put those values in for me, but I would rather figure out why the table isn't doing it the way its supposed to.
 
How are you assigning the values to the PHP variables?

Are you completely sure your variables are null. Try using the [blue]is_null()[/blue] function on your variables to check whether they are null.

Having an empty string as value and being Null is not the same thing.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
i wish i could read
this thread but everything
is cut off at the right and
there's no way to scroll over!!!

how do you know the fields
will not accept NULLs?

could you please do a
SHOW CREATE TABLE and
show the output

perhaps you are inserting
empty strings instead of NULLs?

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top