#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    84
    Rep Power
    14
    If no value in a form field is specified, how do I make mysql input a default value?

    i.e.

    I have a form with first name, last name, and picture (which is the field I want to have a default value for.)

    If the person doesn't pick a file to upload to the mysql database in the form, then I need a default image file is inserted instead.

    The default value specified for the field created when I made the mysql table doesn't work in this case.

    Any help is greatly appreciated.

  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4492
    If you insert a null value into the database, then the default value will take effect. If no picture is selected in a <input file> type box, then usually the $filename = "none". Do a check for this and either input null (so the default will work) or just input the default.

    if($filename="none")
    {
    $filename=null;
    or
    $filename="image/default.gif";
    }
    //do query...

    Hope that helps...

    ---John Holmes...

    ------------------
    *************************************************************
    * The manual can probably answer 90% of your questions...
    *
    * PHP Manual. www.php.net/manual
    * MySQL Manual: www.mysql.com/documentation/mysql/bychapter
    *************************************************************

Similar Threads

  1. Two Steps Query ?
    By Fabiop in forum MySQL Help
    Replies: 5
    Last Post: February 16th, 2004, 11:16 AM
  2. setting default values in column field
    By arthats in forum MySQL Help
    Replies: 1
    Last Post: February 9th, 2004, 10:20 PM
  3. Replies: 1
    Last Post: February 6th, 2004, 05:53 AM
  4. Add $ENV{REMOTE_USER} to end of textarea field on a form
    By k9barry in forum HTML Programming
    Replies: 8
    Last Post: February 4th, 2004, 01:36 PM
  5. Replies: 5
    Last Post: February 3rd, 2004, 01:59 PM

IMN logo majestic logo threadwatch logo seochat tools logo