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!

null value 1

Status
Not open for further replies.

jen0dorf

IS-IT--Management
Apr 15, 2008
104
GB
Hi

created a database with 10 varchar fields for images. A php upload sequence stores the file name in the fields ie. 1.jpg.2,jpg etc etc

However I want to add a default imagecalled say noimage.jpg which is added by default to the image fields. so that when the image is called the noimage.jpg is displayed.

How do i add a default value to the fields?

thanks

Ian
 
When you created the table you should have specified the default value.

Code:
Create Table: CREATE TABLE t (
  image varchar(11) default 'myimage.jpg' auto_increment,
 ...
) ENGINE=MyISAM
If its already created, use the alter command.

Code:
ALTER TABLE tableName ALTER COLUMN columnName SET DEFAULT 'noimage.jpg';


----------------------------------
Phil AKA Vacunita
----------------------------------
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.

Behind the Web, Tips and Tricks for Web Development.
 
Even better: handle this in PHP. You can then also check for existence of the file. A non-existent filename is also "corrupt" data, but it cannot be checked from within the database. This way, you could develop with a copy of a live database without things blowing up.

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
Thanks one and all, I've gone for no 1 option because I'm on a deadline and my php knowledge is a tad small. But I'm climbing the learning curve

thanks again

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top