473,396 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

mysql_affected_rows() question

MS
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.
Nov 12 '07 #1
5 1993
"Warning: mysql_affected_rows(): supplied argument is not a valid
MySQL-Link resource in /home/fakeuser/public_html/test/adduser.php on
line 104"
PHP Manual:
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning
resultset, mysql_query() returns a resource on success, or FALSE on error.
For other type of SQL statements, UPDATE, DELETE, DROP, etc,
mysql_query() returns TRUE on success or FALSE on error.

So: Because TRUE is not a Resource, which is expected.
Ha, that was easy.

Indeed, mysql_affected_rows() does NOT expect the return value of
mysql_query(), but the connection resource:
http://de2.php.net/manual/en/functio...ected-rows.php

So, to but it in a nutshell: RTFM!
Nov 12 '07 #2
MS
Jonas Werres emailed this:
>"Warning: mysql_affected_rows(): supplied argument is not a valid
MySQL-Link resource in /home/fakeuser/public_html/test/adduser.php on
line 104"

PHP Manual:
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning
resultset, mysql_query() returns a resource on success, or FALSE on error.
For other type of SQL statements, UPDATE, DELETE, DROP, etc,
mysql_query() returns TRUE on success or FALSE on error.

So: Because TRUE is not a Resource, which is expected.
Ha, that was easy.

Indeed, mysql_affected_rows() does NOT expect the return value of
mysql_query(), but the connection resource:
http://de2.php.net/manual/en/functio...ected-rows.php

So, to but it in a nutshell: RTFM!
Oh, I'm so sorry! I did RTFM, but *obviously* not very effectively.

Thanks for the help.

Feeling humbled and very sorry.
Nov 12 '07 #3
On Nov 12, 8:15 pm, MS <No.Way.J...@No.Spam.Thank.You.comwrote:
Jonas Werres emailed this:
"Warning: mysql_affected_rows(): supplied argument is not a valid
MySQL-Link resource in /home/fakeuser/public_html/test/adduser.php on
line 104"
PHP Manual:
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning
resultset, mysql_query() returns a resource on success, or FALSE on error.
For other type of SQL statements, UPDATE, DELETE, DROP, etc,
mysql_query() returns TRUE on success or FALSE on error.
So: Because TRUE is not a Resource, which is expected.
Ha, that was easy.
Indeed, mysql_affected_rows() does NOT expect the return value of
mysql_query(), but the connection resource:
http://de2.php.net/manual/en/functio...ected-rows.php
So, to but it in a nutshell: RTFM!

Oh, I'm so sorry! I did RTFM, but *obviously* not very effectively.

Thanks for the help.

Feeling humbled and very sorry.
Well, you shouldn't feel humbled and very sorry, but only sorry.
Don't exaggerate :)

Nov 12 '07 #4
MS
Darko emailed this:
On Nov 12, 8:15 pm, MS <No.Way.J...@No.Spam.Thank.You.comwrote:
>Jonas Werres emailed this:
>>>"Warning: mysql_affected_rows(): supplied argument is not a valid
MySQL-Link resource in /home/fakeuser/public_html/test/adduser.php on
line 104"
PHP Manual:
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning
resultset, mysql_query() returns a resource on success, or FALSE on error.
For other type of SQL statements, UPDATE, DELETE, DROP, etc,
mysql_query() returns TRUE on success or FALSE on error.
So: Because TRUE is not a Resource, which is expected.
Ha, that was easy.
Indeed, mysql_affected_rows() does NOT expect the return value of
mysql_query(), but the connection resource:
http://de2.php.net/manual/en/functio...ected-rows.php
So, to but it in a nutshell: RTFM!
Oh, I'm so sorry! I did RTFM, but *obviously* not very effectively.

Thanks for the help.

Feeling humbled and very sorry.

Well, you shouldn't feel humbled and very sorry, but only sorry.
Don't exaggerate :)
Ok, I take the humbled bit back. I'm just sorry. ;-)
Nov 12 '07 #5
MS wrote:
Jonas Werres emailed this:
>>"Warning: mysql_affected_rows(): supplied argument is not a valid
MySQL-Link resource in /home/fakeuser/public_html/test/adduser.php on
line 104"

PHP Manual:
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning
resultset, mysql_query() returns a resource on success, or FALSE on
error.
For other type of SQL statements, UPDATE, DELETE, DROP, etc,
mysql_query() returns TRUE on success or FALSE on error.

So: Because TRUE is not a Resource, which is expected.
Ha, that was easy.

Indeed, mysql_affected_rows() does NOT expect the return value of
mysql_query(), but the connection resource:
http://de2.php.net/manual/en/functio...ected-rows.php

So, to but it in a nutshell: RTFM!

Oh, I'm so sorry! I did RTFM, but *obviously* not very effectively.

Thanks for the help.

Feeling humbled and very sorry.
Don't worry about it. This area of mysql can be confusing. So many of
the calls take a result from mysql_query(), and you would think that
this one would, also.

But alas, it's (one of) the exception(s) to the "rule". :-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Nov 12 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ben | last post by:
Hi all, I want to store unique data about my page visit. This is done using cookie value. In my database, the page name and cookie value(ip address) are both primary keys. This ensures unique...
3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
10
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
10
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server...
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
5
by: Tyno Gendo | last post by:
Two questions in a row.. I'm on a roll :) When i perform UPDATEs in my admin system, I'm checking for success by using mysql_affected_rows() and this works fine if data is changed and updated. ...
3
by: Sandman | last post by:
Hi, So I read the manual where it says to use mysql_affected_rows() for everything except SELECT and SHOW, and use mysql_num_rows() for those two, which actually return a result. However, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.