Noob Question Php

Discussion in 'PHP' started by DjZoC, Jun 3, 2010.

  1. #1
      if ($Title != "Title?") {
       $query = "INSERT INTO " . $dbtable . " (Title,Weburl,Category,UserIp,AddDate) VALUES ('$Title', '$Weburl', '$Category', '$UserIp', '$AddDate')";
       mysql_query($query);
       $addlink_msg = "Success! Your Video has been added!";
      } else {
       $addlink_msg = "You Mistake Someting!";
      }
    PHP:
    how i can add more if ($Title != "") and if ($Title != " ") echo You Mistake Someting!
     
    Last edited: Jun 3, 2010
    DjZoC, Jun 3, 2010 IP
  2. wigwambam

    wigwambam Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    if($Title!="" && $Title!=" " && $Title!="blah") {
    echo "do something";
    }
     
    wigwambam, Jun 3, 2010 IP
  3. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #3
    ^^ always false, use OR ||
     
    gapz101, Jun 3, 2010 IP
  4. wigwambam

    wigwambam Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Whoops, why did I type &&, as gazp101 says, ||
     
    wigwambam, Jun 3, 2010 IP
  5. w47w47

    w47w47 Peon

    Messages:
    255
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    it depends on what you want to add. it can be && too.
     
    w47w47, Jun 3, 2010 IP
  6. Pudge1

    Pudge1 Well-Known Member

    Messages:
    912
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    Digital Goods:
    1
    #6
    Actually it can't. A variable can't be equal to three different strings ;(
     
    Pudge1, Jun 3, 2010 IP
  7. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #7
    So only we used OR ||

    If you are confused better use Switch Case
     
    roopajyothi, Jun 3, 2010 IP
  8. DjZoC

    DjZoC Member

    Messages:
    167
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #8
    i try with && and is working ! thanks for the help !!!
     
    DjZoC, Jun 3, 2010 IP
  9. cshwebdev

    cshwebdev Active Member

    Messages:
    226
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    80
    #9
    While the current code well work, I could "break" it by putting two spaces, you'd want to apply the trim function to it.

    if(trim($title) != "" && trim($title) != "Title?") {
         echo "We're trying to do something.";
    } else {
         echo "You forgot the title!";
    }
    Code (markup):
     
    cshwebdev, Jun 3, 2010 IP
  10. DjZoC

    DjZoC Member

    Messages:
    167
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #10
    DjZoC, Jun 4, 2010 IP