...

View Full Version : elseif issue



skill_guy101
03-28-2007, 09:35 PM
Thanks for looking!

// 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

koyama
03-29-2007, 03:25 AM
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.

skill_guy101
03-29-2007, 04:06 AM
Brilliant, Problem solved!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum