even if there was no data in the price field when the form was submited the
$price variable exists and isset($price) returns true. May be you could try
!empty($price) instead of isset($price) - Something like.

$query7 = !empty($price) ? "INSERT INTO price (itemid, price) VALUES
($itemid, '$price')" : 0;
$result7 = @pg_Exec($connection, $query7 );

Then when the price field is empty your script will not insert anything into
the database.
You can also modify your select query not to show records without price

select * from price where itemid=50 and price is not Null and price<>"";

Hope this will help
Dobromir Velev

-----Original Message-----
From: Lara J. Fabans <[EMAIL PROTECTED]>
Date: Wednesday, July 25, 2001 7:52 PM
Subject: [PHP-DB] Question on how to test a value

Hi, friends,

Here is how I'm putting the information into the database:
$query7 = isset($price) ? "INSERT INTO price (itemid, price) VALUES
($itemid, '$price')" : 0;
$result7 = @pg_Exec($connection, $query7 );

I'm having difficulties with my test in display.
I've tried isset and == 'NULL' and == '0' as such:

    if ($values2 == 'NULL')
       print "<tr><td class=\"display\">&nbsp;</td></tr>";
    } else
    print "<tr><td class=\"display\">US$


    if (isset($values2))
       print "<tr><td class=\"display\">US$
    } else
    print "<tr><td class=\"display\">&nbsp;</td></tr>";

However, in both cases, if the price doesn't exist in the database, the  US$
still shows up in the

db=> select * from price where itemid=50;
priceid | itemid | price
      48 |     50 |
(1 row)

I was surprised that the insert put something into the database at all.

I could use some advice.

I cleaned up the database to remove all the lines where price wasn't set.
Why is it creating a table row?  If the insert form is passing in where they
didn't set the price,
wouldn't that get picked up by the isset?

And if there isn't a row in the database, wouldn't testing isset of the
result of the query be
sufficient, or should I do a test on $values2->price instead?

I've tried lots of things and nothing seems to be doing the right behavior.
So thanks!

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to