You are here: mysql_affected_rows() question « PHP Programming Language « IT news, forums, messages
mysql_affected_rows() question

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация