Forums
This topic is locked
not null accepts emty field
Posted 23 years ago
1
has voted
23 years ago Jose Ortega posted:
Hello!I am working on a small mySQL database with a PHP-interface. A PHP-form allows the user to enter new recordsets. To make sure that some fields cannot be left empty and that the recordset will only be added to the database if all required fields are filled with data I set the "not null" value in the mySQL database.
My problem now is that a recordset is added to the database even though some required fields (not null) are left empty in the form. Can anybody tell me why? I am looking for something like with Access where you can specify if a field can be left empty or not. I'd like mySQL to give me an error when trying to leave required fields blank.
Thx for your help!
Jose
Replies
Replied 23 years ago
23 years ago Owen Eastwick replied:
Probably the best and easiest method to prevent the user submitting a form with empty fields is to use some JavaScript client side form validation. Look under Behaviours - Validate Form.
Regards
Owen.
Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo
Regards
Owen.
Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo
Replied 23 years ago
23 years ago Tim Green replied:
When creating your database with MySQL you can specify whether a field can be NULL or not.
You can do something like this with the SQL:-
CREATE TABLE Tester (
INDEX_ID int(8) NOT NULL DEFAULT '0' auto_increment,
ITEM text NOT NULL ,
ITEM1 tinyint(8) NOT NULL DEFAULT '0' ,
PRIMARY KEY (INDEX_ID)
}
NOT NULL is quite obviously that the field cannot be blank.
NOT NULL DEFAULT 'whatever' means that the field cannot be blank, but if it is then give it this default value....
Hope this helps.
Tim Green
tim@udzone.com
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
You can do something like this with the SQL:-
CREATE TABLE Tester (
INDEX_ID int(8) NOT NULL DEFAULT '0' auto_increment,
ITEM text NOT NULL ,
ITEM1 tinyint(8) NOT NULL DEFAULT '0' ,
PRIMARY KEY (INDEX_ID)
}
NOT NULL is quite obviously that the field cannot be blank.
NOT NULL DEFAULT 'whatever' means that the field cannot be blank, but if it is then give it this default value....
Hope this helps.
Tim Green
tim@udzone.com
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>