| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		download8000 -
 
  Joined: 28 Dec 2009 Posts: 1
 
  | 
		
			
				 Posted: Mon Dec 28, 2009 2:53 am    Post subject: PHP&MySql Function Problems? | 
				      | 
			 
			
				
  | 
			 
			
				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 | 
		
			           | 
		
	
	
		  | 
	
	
		DonQuichote -
 
  Joined: 24 Dec 2006 Posts: 68 Location: The Netherlands
  | 
		
			
				 Posted: Mon Dec 28, 2009 5:44 pm    Post subject: Check errors | 
				      | 
			 
			
				
  | 
			 
			
				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 | 
		
			          | 
		
	
	
		  | 
	
	
		badai -
 
  Joined: 24 Apr 2003 Posts: 83
 
  | 
		
			
				 Posted: Sat Jan 02, 2010 4:22 pm    Post subject:  | 
				      | 
			 
			
				
  | 
			 
			
				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 | 
		
			          | 
		
	
	
		  | 
	
	
		Toasty -
 
  Joined: 21 Feb 2008 Posts: 298 Location: Chicago, IL
  | 
		
			
				 Posted: Mon Jan 04, 2010 9:39 pm    Post subject:  | 
				      | 
			 
			
				
  | 
			 
			
				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 | 
		
			           | 
		
	
	
		  | 
	
	
		Toasty -
 
  Joined: 21 Feb 2008 Posts: 298 Location: Chicago, IL
  | 
		 | 
	
	
		| Back to top | 
		
			           | 
		
	
	
		  | 
	
	
		 |