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

what is wrong here?

<?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.");
}

}
?>

Dani AI

Generated

The warning mysql_num_rows(): supplied argument is not a valid MySQL result resource means the earlier mysql_query() call returned FALSE instead of a result set. That usually happens because the query failed (syntax, wrong quoting, missing table/column) or because the database connection/resource passed to mysql_query() is invalid or missing. was on the right track about quoting when the code value is non-numeric; the parse error you saw came from putting quotes in the wrong place when trying to assign the GET value.

Quick, practical checks

  • Confirm the include actually creates a valid DB connection and that you pass that resource to your query. Declaring a variable like $c; does nothing — it must hold the connection resource.
  • Right after the query, check for failure and show the DB error while debugging (remove detailed errors in production): use the relevant error function to see why the query failed.
  • Validate incoming data: if code is numeric use intval(); otherwise treat it as a string and escape or use prepared statements. Never trust raw $_GET in SQL.

A modern, safer approach
Use mysqli or PDO with prepared statements to avoid quoting mistakes and SQL injection. Example (mysqli prepared statement):

<?php
$mysqli = new mysqli('host','user','pass','db');
if ($mysqli->connect_error) die('Connect error');
$code = $_GET['code'] ?? '';
$stmt = $mysqli->prepare('SELECT userid FROM confirm WHERE code = ?');
$stmt->bind_param('s', $code);
$stmt->execute();
$res = $stmt->get_result();
if ($res->num_rows === 0) die('Invalid Validation Code');
// proceed with updates using prepared statements
?>

Notes

Recommended Answers

All 9 Replies

If $code is anything other than a number put single quotes around it in the query. eg. '$code'

i did add ' ' but i got a new msg: Parse error: syntax error, unexpected '=' in /home/arash/public_html/activation.php on line 9

Is this line 9? $code=$_GET['code'];

yes

The single quotes need to go around '$code' within the query, not where you are defining the variables. I'm just taking a stab at what you did but line 9 should NOT look like this '$code'=$_GET['code'];

could u please tell me how to fix it?I tried to remove '' and add them ass u sayd...but no results...

If $code is a number this won't make a difference. If $code is a string your queries should look like this $cq=mysql_query("select * from confirm where code='$code' ",$c);

I changed those some lines to:

$code=$_GET['code'];
$cq=mysql_query("select * from confirm WHERE code='$code' ",$c); 
if(mysql_num_array($cq)== 0)

and the new error is:
Fatal error: Call to undefined function mysql_num_array() in /activation.php on line 11

Try this instead if(mysql_num_rows($cq)== 0)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.