TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-15-2009, 04:48 PM   #1 (permalink)
The Acquainted
 
Randy's Avatar
 
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
Randy is on a distinguished road
Default 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
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
Send a message via AIM to Randy Send a message via MSN to Randy
Randy is offline  
Reply With Quote
Old 06-15-2009, 05:32 PM   #2 (permalink)
The Acquainted
 
Randy's Avatar
 
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
Randy is on a distinguished road
Default

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

Any ideas?
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
Send a message via AIM to Randy Send a message via MSN to Randy
Randy is offline  
Reply With Quote
Old 06-15-2009, 06:02 PM   #3 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

What's the next line, or one with mysql_fetch_something?
Salathe is offline  
Reply With Quote
Old 06-15-2009, 06:06 PM   #4 (permalink)
The Acquainted
 
Randy's Avatar
 
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
Randy is on a distinguished road
Default

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
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
Send a message via AIM to Randy Send a message via MSN to Randy
Randy is offline  
Reply With Quote
Old 06-15-2009, 06:10 PM   #5 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

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.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
Randy (06-15-2009)
Old 06-15-2009, 06:10 PM   #6 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

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.
Salathe is offline  
Reply With Quote
Old 06-15-2009, 06:11 PM   #7 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Jinx!
Enjoys the silence.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 06-15-2009, 06:14 PM   #8 (permalink)
The Acquainted
 
Randy's Avatar
 
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
Randy is on a distinguished road
Default

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
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
Send a message via AIM to Randy Send a message via MSN to Randy
Randy is offline  
Reply With Quote
Old 06-15-2009, 06:24 PM   #9 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

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!';

Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
Randy (06-15-2009)
Old 06-15-2009, 06:28 PM   #10 (permalink)
The Acquainted
 
Randy's Avatar
 
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
Randy is on a distinguished road
Default

Thanks again.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
Send a message via AIM to Randy Send a message via MSN to Randy
Randy is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Invalid controller specified ( error ) when dealing with modules in zend framework. Orc General 1 05-21-2009 03:08 PM
Wamp 2 Error Orc General 8 06-20-2008 01:02 PM
Can't solve browser error Peuplarchie Absolute Beginners 1 06-09-2008 05:48 AM
Keep getting mySQL error No. 1064, but i can't seem to find the problem Durux MySQL & Databases 8 04-13-2008 07:51 PM
an error makes me crazy nuts !!!!!!! webtuto Absolute Beginners 1 02-27-2008 10:31 AM


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

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design