Re: Checking for good update

2006-03-13 Thread mysql

On Sun, 12 Mar 2006, Michael Stassen wrote:

 To: [EMAIL PROTECTED]
 From: Michael Stassen [EMAIL PROTECTED]
 Subject: Re: Checking for good update
 
 [EMAIL PROTECTED] wrote:
  looks a bit strange to me.
  
   $result = mysql_query($query) or die('Query couldn\'t
   executed:'.mysql_error());
  
  please try something like this:

 Why?  There's nothing wrong with the above statement.

I've never seen logic like that before. It looks to me like 
fbsd_user is trying to use the OR operator outside an if 
statement.

Is the mentioned in the php manual somewhere Michael?

  I've not tested this - but it looks like you are mixing sending the
  mysql query and testing for the result of the query at the same time,
  which AFAIK is not possible.
 
 You should try it.  It works just fine, and isn't the problem.  The
 problem is that you cannot treat the result of an UPDATE as if it were a
 SELECT.

Regards 

Keith Roberts


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Checking for good update

2006-03-13 Thread Michael Stassen

[EMAIL PROTECTED] wrote:

On Sun, 12 Mar 2006, Michael Stassen wrote:


[EMAIL PROTECTED] wrote:


looks a bit strange to me.


$result = mysql_query($query) or die('Query couldn\'t
executed:'.mysql_error());


please try something like this:


Why?  There's nothing wrong with the above statement.


I've never seen logic like that before. It looks to me like 
fbsd_user is trying to use the OR operator outside an if 
statement.


Is the mentioned in the php manual somewhere Michael?


I've not tested this - but it looks like you are mixing sending the
mysql query and testing for the result of the query at the same time,
which AFAIK is not possible.


You should try it.  It works just fine, and isn't the problem.  The
problem is that you cannot treat the result of an UPDATE as if it were a
SELECT.


Regards 


Keith Roberts


Yes, this is documented.  It's also standard practice (in perl and C as well).

OR is not part of an if statement, it is a logical operator. 
http://www.php.net/manual/en/language.operators.logical.php  A or B has a 
value, true or false, depending on the values of A and of B.  In fact, if A is 
true, then A or B is certainly true, so there's no need to look at B at all. 
This short-circuit evaluation, combined with the fact that every assignment 
returns the assigned value 
http://www.php.net/manual/en/language.expressions.php, makes a statement like 
this possible.


  $result = mysql_query($query) or die('Query error:'.mysql_error());

First, the function mysql_query() is called.  Its return value is assigned to 
$result, *and* returned as the return value of the assignment operator (=).  Now 
we know A.  If mysql_query succeeded, its return value (A) evaluates as true, so 
the or operation must be true, so no need to look at B.  If, on the other hand, 
A is false (mysql_query failed), we must evaluate B to determine the value of 
the or expression.  Of course, to determine the value of B, we have to call 
the referenced function, die().


Michael

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Checking for good update

2006-03-13 Thread mysql

Thankyou for that explanation Michael.

I shall look into using that construct in my own code now!

Apologies to fbsd_user for my previous comments on his 
coding style.

Regards

Keith Roberts

In theory, theory and practice are the same;
In practice they are not. 

On Mon, 13 Mar 2006, Michael Stassen wrote:

 To: [EMAIL PROTECTED]
 From: Michael Stassen [EMAIL PROTECTED]
 Subject: Re: Checking for good update
 
 [EMAIL PROTECTED] wrote:
  On Sun, 12 Mar 2006, Michael Stassen wrote:
   
   [EMAIL PROTECTED] wrote:
   
looks a bit strange to me.

 $result = mysql_query($query) or die('Query couldn\'t
 executed:'.mysql_error());

please try something like this:
   
   Why?  There's nothing wrong with the above statement.
  
  I've never seen logic like that before. It looks to me like fbsd_user
  is trying to use the OR operator outside an if statement.
  
  Is the mentioned in the php manual somewhere Michael?
  
I've not tested this - but it looks like you are mixing
sending the
mysql query and testing for the result of the query at the
same time,
which AFAIK is not possible.
   
   You should try it.  It works just fine, and isn't the problem.
   The
   problem is that you cannot treat the result of an UPDATE as if it
   were a
   SELECT.
  
  Regards 
  Keith Roberts
 
 Yes, this is documented.  It's also standard practice (in perl and C as
 well).
 
 OR is not part of an if statement, it is a logical operator.
 http://www.php.net/manual/en/language.operators.logical.php  A or B
 has a value, true or false, depending on the values of A and of B.  In
 fact, if A is true, then A or B is certainly true, so there's no need to
 look at B at all. This short-circuit evaluation, combined with the fact
 that every assignment returns the assigned value
 http://www.php.net/manual/en/language.expressions.php, makes a statement
 like this possible.
 
   $result = mysql_query($query) or die('Query error:'.mysql_error());
 
 First, the function mysql_query() is called.  Its return value is assigned
 to $result, *and* returned as the return value of the assignment operator
 (=).  Now we know A.  If mysql_query succeeded, its return value (A)
 evaluates as true, so the or operation must be true, so no need to look at
 B.  If, on the other hand, A is false (mysql_query failed), we must
 evaluate B to determine the value of the or expression.  Of course, to
 determine the value of B, we have to call the referenced function, die().
 
 Michael

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



RE: Checking for good update

2006-03-13 Thread fbsd_user
Thank you Michael.  I learned a lot from your detailed explanation
of how the update and select functions work in relation to
checking for good execution.

I used
if (mysql_affected_rows() == 1)
and got the results I was after.

I am stilling having problem with users browser
caching the screen, but will post that as separate question.

Again thanks for your expert help.



-Original Message-
From: Michael Stassen [mailto:[EMAIL PROTECTED]
Sent: Monday, March 13, 2006 4:18 AM
To: [EMAIL PROTECTED]
Cc: mysql@lists.mysql.com
Subject: Re: Checking for good update


[EMAIL PROTECTED] wrote:
 On Sun, 12 Mar 2006, Michael Stassen wrote:

[EMAIL PROTECTED] wrote:

looks a bit strange to me.

$result = mysql_query($query) or die('Query couldn\'t
executed:'.mysql_error());

please try something like this:

Why?  There's nothing wrong with the above statement.

 I've never seen logic like that before. It looks to me like
 fbsd_user is trying to use the OR operator outside an if
 statement.

 Is the mentioned in the php manual somewhere Michael?

I've not tested this - but it looks like you are mixing sending
the
mysql query and testing for the result of the query at the same
time,
which AFAIK is not possible.

You should try it.  It works just fine, and isn't the problem.
The
problem is that you cannot treat the result of an UPDATE as if it
were a
SELECT.

 Regards

 Keith Roberts

Yes, this is documented.  It's also standard practice (in perl and C
as well).

OR is not part of an if statement, it is a logical operator.
http://www.php.net/manual/en/language.operators.logical.php  A or
B has a
value, true or false, depending on the values of A and of B.  In
fact, if A is
true, then A or B is certainly true, so there's no need to look at
B at all.
This short-circuit evaluation, combined with the fact that every
assignment
returns the assigned value
http://www.php.net/manual/en/language.expressions.php, makes a
statement like
this possible.

   $result = mysql_query($query) or die('Query
error:'.mysql_error());

First, the function mysql_query() is called.  Its return value is
assigned to
$result, *and* returned as the return value of the assignment
operator (=).  Now
we know A.  If mysql_query succeeded, its return value (A) evaluates
as true, so
the or operation must be true, so no need to look at B.  If, on the
other hand,
A is false (mysql_query failed), we must evaluate B to determine the
value of
the or expression.  Of course, to determine the value of B, we
have to call
the referenced function, die().

Michael

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/[EMAIL PROTECTED]


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



RE: Checking for good update

2006-03-12 Thread Logan, David (SST - Adelaide)
Perhaps reading the manual would be a good start at
http://us3.php.net/manual/en/function.mysql-num-rows.php

It clearly states 

Retrieves the number of rows from a result set. This command is only
valid for SELECT statements. To retrieve the number of rows affected by
a INSERT, UPDATE, or DELETE query, use mysql_affected_rows().

You are using a function not valid for an UPDATE

Regards

---
** _/ **  David Logan 
***   _/ ***  ITO Delivery Specialist - Database
*_/*  Hewlett-Packard Australia Ltd
_/_/_/  _/_/_/    E-Mail: [EMAIL PROTECTED]
   _/  _/  _/  _/     Desk:   +618 8408 4273
  _/  _/  _/_/_/  Mobile: 0417 268 665
*_/   **
**  _/    Postal: 148 Frome Street,
   _/ **  Adelaide SA 5001
  Australia 
invent   
---

-Original Message-
From: fbsd_user [mailto:[EMAIL PROTECTED] 
Sent: Monday, 13 March 2006 8:00 AM
To: Mysql
Subject: Checking for good update

Using this code I get this error message.

Warning: mysql_num_rows(): supplied argument is not a valid MySQL
result resource in /usr/local/www/data/mls_verifyemail.php on line
49

What code should I use to check if the update worked or not?


$query = UPDATE members SET email_verified='X' WHERE
logon_id='.$logonid.';

$result = mysql_query($query) or die('Query couldn\'t
executed:'.mysql_error());

if (mysql_num_rows($result) == 1)
{
 // the user id and password match,
 print(User id on db);
}
else
{
 //$errorMessage = 'Sorry, wrong user id / password';
 print(Sorry, wrong user id / password);

}


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



RE: Checking for good update

2006-03-12 Thread fbsd_user


All ready read that and its clear as mud.
It tells you update is different but gives no example.

I asked in my post what should I code for checking the result of a
update.



-Original Message-
From: Logan, David (SST - Adelaide) [mailto:[EMAIL PROTECTED]
Sent: Sunday, March 12, 2006 4:50 PM
To: [EMAIL PROTECTED]; Mysql
Subject: RE: Checking for good update


Perhaps reading the manual would be a good start at
http://us3.php.net/manual/en/function.mysql-num-rows.php

It clearly states

Retrieves the number of rows from a result set. This command is only
valid for SELECT statements. To retrieve the number of rows affected
by
a INSERT, UPDATE, or DELETE query, use mysql_affected_rows().

You are using a function not valid for an UPDATE

Regards

---
** _/ **  David Logan
***   _/ ***  ITO Delivery Specialist - Database
*_/*  Hewlett-Packard Australia Ltd
_/_/_/  _/_/_/    E-Mail: [EMAIL PROTECTED]
   _/  _/  _/  _/     Desk:   +618 8408 4273
  _/  _/  _/_/_/  Mobile: 0417 268 665
*_/   **
**  _/    Postal: 148 Frome Street,
   _/ **  Adelaide SA 5001
  Australia
invent
---

-Original Message-
From: fbsd_user [mailto:[EMAIL PROTECTED]
Sent: Monday, 13 March 2006 8:00 AM
To: Mysql
Subject: Checking for good update

Using this code I get this error message.

Warning: mysql_num_rows(): supplied argument is not a valid MySQL
result resource in /usr/local/www/data/mls_verifyemail.php on line
49

What code should I use to check if the update worked or not?


$query = UPDATE members SET email_verified='X' WHERE
logon_id='.$logonid.';

$result = mysql_query($query) or die('Query couldn\'t
executed:'.mysql_error());

if (mysql_num_rows($result) == 1)
{
 // the user id and password match,
 print(User id on db);
}
else
{
 //$errorMessage = 'Sorry, wrong user id / password';
 print(Sorry, wrong user id / password);

}


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/[EMAIL PROTECTED]


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Checking for good update

2006-03-12 Thread mysql

looks a bit strange to me.

 $result = mysql_query($query) or die('Query couldn\'t
 executed:'.mysql_error());

please try something like this:

// build the query - (that's OK)
$query = UPDATE members SET email_verified='X' WHERE
logon_id=' .$logonid. ';
 
// send the query to the server - save the result resource
$res = mysql_query($query);

// test for the result of the above query
if(!$res)
  {
  // stop the script if the result is not valid
  die('Query couldn\'t be executed:'.mysql_error());
  }

// process a valid result
$row = mysql_fetch_array($res)

if (mysql_num_rows($res) == 1)
  {
  // the user id and password match,
  print(User id on db);
  }
else
  {
  //$errorMessage = 'Sorry, wrong user id / password';
  print(Sorry, wrong user id / password);
  }

I've not tested this - but it looks like you are mixing sending the
mysql query and testing for the result of the query at the same time,
which AFAIK is not possible.

Maybe you need to get a simple introductory book on php, such as O'reillys
php pocket reference, ISBN 0596-00402-8.

Regards 

Keith

In theory, theory and practice are the same;
In practice they are not. 

On Sun, 12 Mar 2006, fbsd_user wrote:

 To: Mysql mysql@lists.mysql.com
 From: fbsd_user [EMAIL PROTECTED]
 Subject: Checking for good update
 
 Using this code I get this error message.
 
 Warning: mysql_num_rows(): supplied argument is not a valid MySQL
 result resource in /usr/local/www/data/mls_verifyemail.php on line

Probably because you are not sending a valid query to the server,
you will not be getting a valid result resource back from the server.

 What code should I use to check if the update worked or not?
 
 
 $query = UPDATE members SET email_verified='X' WHERE
 logon_id='.$logonid.';
 
 $result = mysql_query($query) or die('Query couldn\'t
 executed:'.mysql_error());
 
 if (mysql_num_rows($result) == 1)
 {
// the user id and password match,
print(User id on db);
   }
   else
   {
//$errorMessage = 'Sorry, wrong user id / password';
print(Sorry, wrong user id / password);
   }

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Checking for good update

2006-03-12 Thread mysql
Maybe I need to read the copy of php pocket reference I have 
to David - LOL.

Keith

On Sun, 12 Mar 2006 [EMAIL PROTECTED] wrote:

 To: mysql@lists.mysql.com
 From: [EMAIL PROTECTED]
 Subject: Re: Checking for good update
 
 
 looks a bit strange to me.
 
  $result = mysql_query($query) or die('Query couldn\'t
  executed:'.mysql_error());
 
 please try something like this:
 
 // build the query - (that's OK)
 $query = UPDATE members SET email_verified='X' WHERE
 logon_id=' .$logonid. ';
  
 // send the query to the server - save the result resource
 $res = mysql_query($query);
 
 // test for the result of the above query
 if(!$res)
   {
   // stop the script if the result is not valid
   die('Query couldn\'t be executed:'.mysql_error());
   }
 
 // process a valid result
 $row = mysql_fetch_array($res)
 
 if (mysql_num_rows($res) == 1)
   {
   // the user id and password match,
   print(User id on db);
   }
 else
   {
   //$errorMessage = 'Sorry, wrong user id / password';
   print(Sorry, wrong user id / password);
   }
 
 I've not tested this - but it looks like you are mixing sending the
 mysql query and testing for the result of the query at the same time,
 which AFAIK is not possible.
 
 Maybe you need to get a simple introductory book on php, such as O'reillys
 php pocket reference, ISBN 0596-00402-8.
 
 Regards 
 
 Keith
 
 In theory, theory and practice are the same;
 In practice they are not. 
 
 On Sun, 12 Mar 2006, fbsd_user wrote:
 
  To: Mysql mysql@lists.mysql.com
  From: fbsd_user [EMAIL PROTECTED]
  Subject: Checking for good update
  
  Using this code I get this error message.
  
  Warning: mysql_num_rows(): supplied argument is not a valid MySQL
  result resource in /usr/local/www/data/mls_verifyemail.php on line
 
 Probably because you are not sending a valid query to the server,
 you will not be getting a valid result resource back from the server.
 
  What code should I use to check if the update worked or not?
  
  
  $query = UPDATE members SET email_verified='X' WHERE
  logon_id='.$logonid.';
  
  $result = mysql_query($query) or die('Query couldn\'t
  executed:'.mysql_error());
  
  if (mysql_num_rows($result) == 1)
  {
   // the user id and password match,
   print(User id on db);
  }
  else
  {
   //$errorMessage = 'Sorry, wrong user id / password';
   print(Sorry, wrong user id / password);
  }
 
 -- 
 MySQL General Mailing List
 For list archives: http://lists.mysql.com/mysql
 To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
 
 

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



RE: Checking for good update

2006-03-12 Thread fbsd_user

Maybe I have the overall logic wrong.

I don't do a select query first to see if that record is there.
I just try to update it.

If the logonid key in the update request is on the table, the record
does get updated. I can verify that using phpmyadmin.

When the logonid key in the update request is not on the table, the
results checks still take the record successful updated condition. A
look at the table using phpmyadmin shows me that there is no record
matching that logonid key.

My last test I tried this
if ($results == TRUE)

and still the update was successful condition is taken even when the
update key value is not on the table. I would expect the update was
unsuccessful condition to have been taken.

So the basic question boils down to   why does the successful
condition always get taken even when there is no match on the table
for the key value being used?

This is testing a new developed script, so there may be a logic
error in how things are done in the script. But I need to have the
results of the update to be able to tell difference between a good
update and one where the key used to target the record is not on the
table.

How do you suggest I should code the result condition test?

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Sunday, March 12, 2006 5:20 PM
To: mysql@lists.mysql.com
Subject: Re: Checking for good update


Maybe I need to read the copy of php pocket reference I have
to David - LOL.

Keith

On Sun, 12 Mar 2006 [EMAIL PROTECTED] wrote:

 To: mysql@lists.mysql.com
 From: [EMAIL PROTECTED]
 Subject: Re: Checking for good update


 looks a bit strange to me.

  $result = mysql_query($query) or die('Query couldn\'t
  executed:'.mysql_error());

 please try something like this:

 // build the query - (that's OK)
 $query = UPDATE members SET email_verified='X' WHERE
 logon_id=' .$logonid. ';

 // send the query to the server - save the result resource
 $res = mysql_query($query);

 // test for the result of the above query
 if(!$res)
   {
   // stop the script if the result is not valid
   die('Query couldn\'t be executed:'.mysql_error());
   }

 // process a valid result
 $row = mysql_fetch_array($res)

 if (mysql_num_rows($res) == 1)
   {
   // the user id and password match,
   print(User id on db);
   }
 else
   {
   //$errorMessage = 'Sorry, wrong user id / password';
   print(Sorry, wrong user id / password);
   }

 I've not tested this - but it looks like you are mixing sending
the
 mysql query and testing for the result of the query at the same
time,
 which AFAIK is not possible.

 Maybe you need to get a simple introductory book on php, such as
O'reillys
 php pocket reference, ISBN 0596-00402-8.

 Regards

 Keith

 In theory, theory and practice are the same;
 In practice they are not.

 On Sun, 12 Mar 2006, fbsd_user wrote:

  To: Mysql mysql@lists.mysql.com
  From: fbsd_user [EMAIL PROTECTED]
  Subject: Checking for good update
 
  Using this code I get this error message.
 
  Warning: mysql_num_rows(): supplied argument is not a valid
MySQL
  result resource in /usr/local/www/data/mls_verifyemail.php on
line

 Probably because you are not sending a valid query to the server,
 you will not be getting a valid result resource back from the
server.

  What code should I use to check if the update worked or not?
 
 
  $query = UPDATE members SET email_verified='X' WHERE
  logon_id='.$logonid.';
 
  $result = mysql_query($query) or die('Query couldn\'t
  executed:'.mysql_error());
 
  if (mysql_num_rows($result) == 1)
  {
   // the user id and password match,
   print(User id on db);
  }
  else
  {
   //$errorMessage = 'Sorry, wrong user id / password';
   print(Sorry, wrong user id / password);
  }

 --
 MySQL General Mailing List
 For list archives: http://lists.mysql.com/mysql
 To unsubscribe:
http://lists.mysql.com/[EMAIL PROTECTED]



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/[EMAIL PROTECTED]


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Checking for good update

2006-03-12 Thread Michael Stassen

fbsd_user wrote:
 Using this code I get this error message.

 Warning: mysql_num_rows(): supplied argument is not a valid MySQL
 result resource in /usr/local/www/data/mls_verifyemail.php on line 49

 What code should I use to check if the update worked or not?

Your second line does just that.

 $query = UPDATE members SET email_verified='X' WHERE
 logon_id='.$logonid.';

 $result = mysql_query($query) or die('Query couldn\'t
 executed:'.mysql_error());

Right there.  You told php to die and print the error from mysql if the update 
failed.


 if (mysql_num_rows($result) == 1)
   {
 // the user id and password match,
 print(User id on db);
}
else
{
 //$errorMessage = 'Sorry, wrong user id / password';
 print(Sorry, wrong user id / password);
}

The rest of the code only makes sense for a select, but you did an update. 
mysql_num_rows() tells the number of rows of data returned by a select.  No 
select, no returned rows, no mysql_num_rows()  --  hence the error message.


Logan, David (SST - Adelaide) wrote:
 Perhaps reading the manual would be a good start at
 http://us3.php.net/manual/en/function.mysql-num-rows.php

 It clearly states

 Retrieves the number of rows from a result set. This command is only
 valid for SELECT statements. To retrieve the number of rows affected by
 a INSERT, UPDATE, or DELETE query, use mysql_affected_rows().

 You are using a function not valid for an UPDATE

fbsd_user wrote:

 All ready read that and its clear as mud.
 It tells you update is different but gives no example.

 I asked in my post what should I code for checking the result of a
 update.

Please reread David's post, as he gave you the answer in the quote from the 
manual.  Use mysql_affected_rows() to get the number of rows affected by an 
UPDATE.  There are a few caveats, however.  See the manual for details 
http://www.php.net/manual/en/function.mysql-affected-rows.php.


fbsd_user wrote:
 Maybe I have the overall logic wrong.

I think perhaps you do.

 I don't do a select query first to see if that record is there.
 I just try to update it.

Then it will be difficult to know for certain, in that scenario, whether or not 
a row was matched.


 If the logonid key in the update request is on the table, the record
 does get updated. I can verify that using phpmyadmin.

 When the logonid key in the update request is not on the table, the
 results checks still take the record successful updated condition. A
 look at the table using phpmyadmin shows me that there is no record
 matching that logonid key.

That's right.  Your query is

  UPDATE members SET email_verified='X' WHERE logon_id=$logonid;

You are asking mysql to set the email_verified column to 'X' for every row in 
the table which has the given logon_id.  The success of this query is not 
determined by the number of rows matched.  If no rows match, mysql will 
successfully update 0 rows (just as it will successfully update 13 rows, if 
13 rows match).  That is not an error, as it is precisely what you requested.


 My last test I tried this
 if ($results == TRUE)

 and still the update was successful condition is taken even when the
 update key value is not on the table. I would expect the update was
 unsuccessful condition to have been taken.

No.  The query worked.  It successfully updated all 0 matching rows.

 So the basic question boils down to why does the successful
 condition always get taken even when there is no match on the table
 for the key value being used?

Because success of a query does not depend on the existence of rows which match 
its WHERE clause.  Success depends on parsing and executing the query.


 This is testing a new developed script, so there may be a logic
 error in how things are done in the script. But I need to have the
 results of the update to be able to tell difference between a good
 update and one where the key used to target the record is not on the
 table.

 How do you suggest I should code the result condition test?

As David suggested, you can use mysql_affected_rows() to find how many rows were 
affected by your update.  This will certainly be 0 if there is no matching row. 
 You need to be aware, however, that it will also be zero if the matching 
row(s) already has email_verified='X', because mysql will not waste time 
changing a row for which the new value is the same as the old value.  If that's 
a possibility, you could try parsing the outut of mysql_info().  See the manual 
for details http://www.php.net/manual/en/function.mysql-info.php.


Michael

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Checking for good update

2006-03-12 Thread Michael Stassen

[EMAIL PROTECTED] wrote:

looks a bit strange to me.


$result = mysql_query($query) or die('Query couldn\'t
executed:'.mysql_error());


please try something like this:


Why?  There's nothing wrong with the above statement.


// build the query - (that's OK)
$query = UPDATE members SET email_verified='X' WHERE
logon_id=' .$logonid. ';
 
// send the query to the server - save the result resource

$res = mysql_query($query);

// test for the result of the above query
if(!$res)
  {
  // stop the script if the result is not valid
  die('Query couldn\'t be executed:'.mysql_error());
  }


Fine so far, but the code below repeats the problem.  There are no rows to 
process, because there was no SELECT.



// process a valid result
$row = mysql_fetch_array($res)

if (mysql_num_rows($res) == 1)
  {
  // the user id and password match,
  print(User id on db);
  }
else
  {
  //$errorMessage = 'Sorry, wrong user id / password';
  print(Sorry, wrong user id / password);
  }

I've not tested this - but it looks like you are mixing sending the
mysql query and testing for the result of the query at the same time,
which AFAIK is not possible.


You should try it.  It works just fine, and isn't the problem.  The problem is 
that you cannot treat the result of an UPDATE as if it were a SELECT.


snip


Using this code I get this error message.

Warning: mysql_num_rows(): supplied argument is not a valid MySQL
result resource in /usr/local/www/data/mls_verifyemail.php on line


Probably because you are not sending a valid query to the server,
you will not be getting a valid result resource back from the server.


The query was valid, and it worked, but mysql_num_rows() is only for SELECTs.

Michael

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]