Forums

This topic is locked

not null accepts emty field

Posted 05 Dec 2001 16:51:21
1
has voted
05 Dec 2001 16:51:21 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 05 Dec 2001 17:48:48
05 Dec 2001 17:48:48 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
Replied 14 Dec 2001 15:22:25
14 Dec 2001 15:22:25 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

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>

Reply to this topic