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

    Join Date
    Aug 2000
    Location
    Sacramento
    Posts
    50
    Rep Power
    15
    Hello,

    I have a form that updates a database. On this form I have an optional, comments box. I want to make a script that, if I enter something in this comment box, it takes those comments and adds to them a phrase called "Your comments were: $comments"

    this can easily be done like this $message = "Your comments were: $comments"

    Then , in the email I can place $message and it's done. The problem is, if the user doesn't enter a comment, based on the above example they would get this: "Your comments were:"

    How can I have it so that only if the comments box is entered, does it add the description "Your comments were:"

    Do I use an if / else statement?

    Thank you very much for your help.
  2. #2
  3. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    17
    Do this:

    if (isset($comments)) {

    $message = "Your comments were: $comments";

    }

    else {

    $message = "";

    }

    Hope this helps,

    --------------------------------------------
    Alex
    (http://www.alex-greg.co.uk)
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Sacramento
    Posts
    50
    Rep Power
    15
    Thanks alot alex! I'll try that.

IMN logo majestic logo threadwatch logo seochat tools logo