TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   MySQL & Databases (http://www.talkphp.com/mysql-databases/)
-   -   Error? (http://www.talkphp.com/mysql-databases/4558-error.html)

Randy 06-15-2009 04:48 PM

Error?
 
So im running an insert for stuff on my script and im getting this error:

Quote:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\staff\admin\index.php on line 275
My code:
PHP Code:

LINE 274$sql2="INSERT INTO adminforum_question(topic, detail, name, category, priority, datetime)VALUES('$topic', '$detail', '$name', '$category', '$priority', '$datetime')";
LINE 275$result=mysql_query($sql2); 

Not sure whats wrong with it as I copied it from another script I have.

Thanks,
Randy

Randy 06-15-2009 05:32 PM

It seems to actually do what it was supposed to but i still get that error..

Any ideas?

Salathe 06-15-2009 06:02 PM

What's the next line, or one with mysql_fetch_something?

Randy 06-15-2009 06:06 PM

PHP Code:

LINE 274$sql2="INSERT INTO adminforum_question(topic, detail, name, category, priority, datetime)VALUES('$topic', '$detail', '$name', '$category', '$priority', '$datetime')";
LINE 275$result=mysql_query($sql2);
LINE 276: if(mysql_num_rows($result) > 0


Wildhoney 06-15-2009 06:10 PM

Isn't mysql_num_rows for SELECT, and mysql_affected_rows for INSERT? It is a while since I communicated with the MySQL functions directly, but I am sure you're looking for mysql_affected_rows in that scenario, not mysql_num_rows.

Salathe 06-15-2009 06:10 PM

Aha! You're using mysql_num_rows on a query which doesn't return any. For INSERT, DELETE, etc. you can use mysql_affected_rows to see how many were affected by the query.

Edit: WH beat me to it, but yes 'affected' for queries that don't return a result set.

Wildhoney 06-15-2009 06:11 PM

Jinx!
Enjoys the silence.

Randy 06-15-2009 06:14 PM

Still getting an error:

Quote:

Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in C:\xampp\htdocs\staff\admin\index.php on line 275
CODE:
PHP Code:

LINE 273$sql2="INSERT INTO adminforum_question(topic, detail, name, category, priority, datetime)VALUES('$topic', '$detail', '$name', '$category', '$priority', '$datetime')";
LINE 274$result=mysql_query($sql2);
LINE 275: if(mysql_affected_rows($result) > 0


Salathe 06-15-2009 06:24 PM

You don't need to provide an argument to mysql_affected_rows because no result set is being returned from mysql_query. The only argument (and it's optional) would be if you wanted to specify the MySQL connection link.

PHP Code:

if (mysql_affected_rows() > 0) {
    echo 
'Some rows were affected!';



Randy 06-15-2009 06:28 PM

Thanks again.


All times are GMT. The time now is 04:08 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0