Re: [PHP] a conditionial insert

2002-11-18 Thread Justin French
Hi,

on 19/11/02 1:51 PM, Peter Houchin ([EMAIL PROTECTED]) wrote:

 function new_user() {
 //check to see if the company is in the list
 
 
 $result = mysql_query(SELECT * FROM resellers WHERE
 company='$_POST[company]');
 // if it's not then ...
 if ($result == FALSE){
 blah
 }
 //if it is then insert the rest of the stuff to the db
 else {
 $res = mysql_query(INSERT)
 }
 
 but doing it this way doesn't seem to help.. any one got any idea's?

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



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] a conditionial insert

2002-11-18 Thread Peter Houchin

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
 




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] a conditionial insert

2002-11-18 Thread Justin French
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 ([EMAIL PROTECTED]) 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



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] a conditionial insert

2002-11-18 Thread Jason Wong
On Tuesday 19 November 2002 11:13, Justin French wrote:
 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 -- 

  if (A AND B)

B only gets evaluated only if A is true, so it's quite safe to do this:

  if ($result  mysql_num_rows($result)  1)

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
Never put off until tomorrow what you can do today.  There might be a
law against it by that time.
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php