Re: a conditionial insert
| From: | Justin French | Date: | Tue, 19 Nov 2002 03:13:16 +0000 |
| Subject: | Re: a conditionial insert | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-125023@lists.php.net to get a copy of this message | ||
Depends on hwo you want your logic to work, but I think what you have isn't
terribly accurate, because you're testing $result and mysql_num_rows() at
the same time -- it's hard to explain...... perhaps you should actually do
this:
if($result)
{
if(mysql_num_rows($result) > 0)
{
// do this
}
else
{
// do this
}
}
else
{
echo "mysql query failed " . mysql_error() . "<br />";
}
JF
on 19/11/02 2:10 PM, Peter Houchin (php@vfsa.com.au) wrote:
>
> Hi
>
> just wanted to say thanks Justin.. I've got it working with your idea .... I
> needed to change this line....
>
> if($result && mysql_num_rows($result) > 0)
>
> to
>
> if ($result && mysql_num_rows($result) < 1)
>
> and it works a treat.
>
> Thanks
>
> Peter
>
>> I'm no expert, but I think $result will return true if the query was
>> successful, it's not dependant on if there were rows returned.
>>
>> To check if there was a row returned, use mysql_num_rows($result)
>>
>>
>> $result = mysql_query("SELECT * FROM resellers WHERE
>> company='$_POST[company]'");
>> if($result && mysql_num_rows($result) > 0)
>> {
>> // insert
>> }
>> else
>> {
>> //something else
>> }
>>
>>
>>
>> Justin French
>> --------------------
>> http://Indent.com.au
>> Web Developent &
>> Graphic Design
>> --------------------
>>
>>
>
Justin French
--------------------
http://Indent.com.au
Web Developent &
Graphic Design
--------------------