PHP&MySql Function Problems?

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
download8000
-


Joined: 28 Dec 2009
Posts: 1

PostPosted: Mon Dec 28, 2009 2:53 am    Post subject: PHP&MySql Function Problems? Reply with quote

I'm getting an erro when trying to count the number of records obtained from a mysql db. the error states:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Program Files\Abyss Web Server\htdocs\login.php on line 6

the code is:

$db = mysql_connect("localhost", "root");
mysql_select_db("itjobhunt", $db);
$sql = "Select * FROM agency WHERE agy_ID = '" + $agy_Account + "'";
$result = mysql_query($sql);
$results = mysql_num_rows($result);
echo "<br>$results<br>";

I have an idea that this may be to do with the setup of PHP but may be completely wrong. Any idea's??
Back to top View user's profile Send private message Visit poster's website
DonQuichote
-


Joined: 24 Dec 2006
Posts: 68
Location: The Netherlands

PostPosted: Mon Dec 28, 2009 5:44 pm    Post subject: Check errors Reply with quote

You do not check for any errors in your code. So don't ask us what is wrong, ask your system. The mysql_error function has the message. You may not even get a connection (check that you get a resource). If you do get a connection, every call to a mysql_* function should be followed by a check on mysql_errno(), and if it returns anything else than zero, check the error message in mysql_error(). Furthermore, the variable $agy_Account could be empty. If this is a case of ancient code that relies on automatically created variables from post parameters or even magic quotes, update the code.

But if you have this code on a public server,
- implement error handling. Really. And that means communicating the technical exact error messages to you, not to the visitor of the web site.
- never, never use unfiltered user input in queries. Never.
- switch display of warnings and errors OFF on the live server, and ON on your development machine.
Back to top View user's profile Send private message
badai
-


Joined: 24 Apr 2003
Posts: 82

PostPosted: Sat Jan 02, 2010 4:22 pm    Post subject: Reply with quote

long way to go...

seem like you confusing javascript with php. + for joining string in script, . (dot) for php.

the error tells u mysql_num_rows have problem executing with given parameter (the $result).

also, try not to reuse variable name. you should use something like this for number of result:

$num = mysql_num_rows($result)

that way, you can access $result later.

but i don't put too much hope u understand anything i said anyway.

good luck man.
Back to top View user's profile Send private message
Toasty
-


Joined: 21 Feb 2008
Posts: 298
Location: Chicago, IL

PostPosted: Mon Jan 04, 2010 9:39 pm    Post subject: Reply with quote

Code is messed up. Fix the code via the errors that PHP is spitting out like crazy, and I'll help you figure out the mysql portion. I assume you're not getting a connection to the database "using password: no".
_________________
Audit the secure configuration of your server headers!
Back to top View user's profile Send private message Visit poster's website
Toasty
-


Joined: 21 Feb 2008
Posts: 298
Location: Chicago, IL

PostPosted: Mon Jan 04, 2010 9:39 pm    Post subject: Reply with quote

>Got a 500 error, reposted. Delete this post please. <
_________________
Audit the secure configuration of your server headers!
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group