2 Replies - 1530 Views - Last Post: 11 October 2009 - 10:35 PM Rate Topic: -----

#1 amail  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-October 09

Warning: mysql_num_rows(): supplied argument is not a valid MySQL resu

Posted 11 October 2009 - 10:28 AM

hi
can someone please help me? i am trying to send activation code to new member and i get only wrong msg in my files....

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/arash/public_html/activation.php on line 11
Invalid Validation Code

here is the file:
<?php
session_start();
include "mysql.php";
$c;
if(!$_GET['code'] || !$_GET['act'])
{
die("Invalid Use Of System.");
} else {
$code=$_GET['code'];
$cq=mysql_query("select * from confirm where code=$code",$c);
if(mysql_num_rows($cq)== 0)
{ die("Invalid Validation Code"); }
$r=mysql_fetch_array($cq);
if($_GET['act'] == 'activate')
{
mysql_query("UPDATE users SET confirmed='1' WHERE userid={$r[user]}",$c);
mysql_query("DELETE FROM confirm WHERE code=$code",$c);
print "Account Validated!<br />
<a href='login.php'>Login</a>";
 } else if($_GET[act] == 'cancel')
{
mysql_query("DELETE FROM users WHERE userid={$r[user]}",$c);
mysql_query("DELETE FROM confirm WHERE code=$code",$c);
print "Your account has successfully been cancelled, Were sorry you had to leave.";exit;
} else {
die("Invalid Action.");
}

}
?>


Is This A Good Question/Topic? 0
  • +

Replies To: Warning: mysql_num_rows(): supplied argument is not a valid MySQL resu

#2 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL resu

Posted 11 October 2009 - 09:10 PM

it seems that problem is in your query, try to add die(); function after query some thing like this:
...$cq=mysql_query("select * from confirm where code=$code",$c)or die(mysql_error());...
Was This Post Helpful? 0
  • +
  • -

#3 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 541
  • View blog
  • Posts: 1,708
  • Joined: 08-November 08

Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL resu

Posted 11 October 2009 - 10:35 PM

$code should be in single quotes in your query, like this:

$cq=mysql_query("select * from confirm where code='$code'",$c);

The suggestion above is also a good one after any query execution. It's incredibly useful during the debugging process.

I would also like to suggest that, if mysql.php initializes $c as the database connection link identifier, there is no need for the $c; line at all.

Also, using $_GET directly in a query is a really easy way to open yourself to SQL Injection attacks. You might want to sanitize your input first.

This post has been edited by Valek: 11 October 2009 - 10:35 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1