Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: elseif issue

  1. #1
    New Coder
    Join Date
    Feb 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    elseif issue

    Thanks for looking!
    PHP Code:
    // Retrieve Values
     
    $giftid $_POST["giftid"];
     
    $gift $_POST["gift"];
     
    $shop $_POST["shop"];
     
    $category $_POST["category"];
     
    $price $_POST["price"];

     
    $newgift $_POST["newgift"];
     
    $newshop $_POST["newshop"];
     
    $newcategory $_POST["newcategory"];
     
    $newprice $_POST["newprice"];


    // Update
    if ( $giftid !== "") {
    mysql_query("UPDATE gift SET gift='$gift',  shop='$shop', category='$category', price='$price' WHERE giftid='$giftid' "
    or die(
    mysql_error());  
    }

    // Insert
    elseif ( $newgift !== "") {
    mysql_query("INSERT INTO gift (gift, shop, category, price) VALUES ('$newgift', '$newshop', '$newcategory', '$newprice' ) "
    or die(
    mysql_error());  

    The elseif part doesn't work. This is probably a classic error but I cant seem to find it on my own.

    here is the live page http://www.danstaley.com/wedding/add.php
    the values in the form are posted back into the top of the page, where this code is situated.

    Thanks,

    Dan

  • #2
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by skill_guy101 View Post
    The elseif part doesn't work. This is probably a classic error but I cant seem to find it on my own.
    When you use !== , this means 'not identical to' in both type and value. That is not the same as != which is not quite as strict (Using this one instead would probably solve the problem)

    So your first if condition is also true when $giftid is not set or null. That would be the case for your 'add' form.

  • #3
    New Coder
    Join Date
    Feb 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Brilliant, Problem solved!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •