|
Posted by MS on 11/12/07 17:51
Hi,
I'm doing a table insert and have a question about mysql_affected_rows().
The following code works. It correctly inserts the row and
mysql_affected_rows() returns 1 as it should do.
$sql = "INSERT INTO member (company, username, password, cookie,
session, ip) VALUES ('$company', '$user', '$pass', 'fakecookie',
'fakesession', '192.168.1.1')";
$result = mysql_query($sql) or MyDie("Error: ".mysql_error());
// Determine success:
// mysql_affected_rows returns the number of affected rows on
// success, and -1 if the last query failed.
$rowsAffected = mysql_affected_rows();
However the final line, the call to mysql_affected_rows, used to have
$result as an argument, like this:
$rowsAffected = mysql_affected_rows($result);
Which as far as I can tell is correct. When I use that line, the row gets
inserted correctly, but the call to mysql_affected_rows() fails, with the
following error message:
"Warning: mysql_affected_rows(): supplied argument is not a valid
MySQL-Link resource in /home/fakeuser/public_html/test/adduser.php on line
104"
I don't understand why it is not a valid link resource. The almost
identical code, but making a 'select' query and not doing an 'insert',
works fine when checking with 'mysql_num_rows($result)'.
Obviously this is not critical, since I've got it working, but in the
interests of increasing my understanding can someone explain this problem
to me please.
Many thanks.
Navigation:
[Reply to this message]
|