FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Activation Script





fromegame
It's me again Razz
I just don't get what's wrong with this script...
When registering there will be made an 'id' (auto_increment) and an MD5 of the username. There will an e-mail been send: http://www.frome.frih.net/activate.php?key=$key&id=$id. But it doesn't work. He does send the e-mail, but if you click on the link in the e-mail he says this:

Code:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/fromegam/domains/frome.frih.net/public_html/activate.php on line 24


PS: Later on I will change the MD5 to generate_key or something.

Code:

$host="localhost"; // Host name
$username="xxx"; // Mysql username
$password="xxx"; // Mysql password
$db_name="xxx"; // Database name
$tbl_name="xxx"; // Table name



mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");



$id = $_GET['id'];
$key = $_GET['key'];

$sql="SELECT * FROM $tbl_name WHERE id='$id' AND key='$key'";
$result=mysql_query($sql);




$count=mysql_num_rows($result);


if($count==1){

echo "good";

}

else {

echo "bad";

}
hexkid
fromegame wrote:
I just don't get what's wrong with this script...

Try the suggestion in my signature Smile
fromegame
Code:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/fromegam/domains/frome.frih.net/public_html/activate.php on line 25


Still the same Mad
ncwdavid
Will you post the script that sends the link? that would really help. Plus i think that error is coming up because there is no vlaue for $id or $key but the script is really needed to speed up figuring out the problem.
hexkid
fromegame wrote:
Still the same Mad


Ok ... now try this:

Code:
// ...
$sql="SELECT * FROM $tbl_name WHERE id='$id' AND key='$key'";
$result=mysql_query($sql)or die("cannot execute query");
// ...


You can have MySQL tell you why it couldn't execute the query
Code:
// ...
$sql="SELECT * FROM $tbl_name WHERE id='$id' AND key='$key'";
$result=mysql_query($sql)or die("cannot execute query, because " . mysql_error());
// ...
fromegame
hexkid wrote:
fromegame wrote:
Still the same Mad


Ok ... now try this:

Code:
// ...
$sql="SELECT * FROM $tbl_name WHERE id='$id' AND key='$key'";
$result=mysql_query($sql)or die("cannot execute query");
// ...


You can have MySQL tell you why it couldn't execute the query
Code:
// ...
$sql="SELECT * FROM $tbl_name WHERE id='$id' AND key='$key'";
$result=mysql_query($sql)or die("cannot execute query, because " . mysql_error());
// ...


Ok, query is right now, first he said syntax error, now he doesn't say that anymore. Now he says: 'bad'...
So something wrong with the mysql_num_rows Embarassed ?
hexkid
That's because $count is not 1. It is either 2, 3, or more, or 0 (zero)

fromegame wrote:
Code:
// ...
if($count==1){

echo "good";

}

else {

echo "bad";

}
// ...


Print the query as PHP sees it, and try it in PHPMyAdmin or some other interactive MySQL thingie

Code:
$sql="SELECT * FROM $tbl_name WHERE id='$id' AND key='$key'";
$result=mysql_query($sql);

### Print the SQL statement to try in PHPMyAdmin
echo "PHP sent this statement to MySQL: <b><tt>$sql</tt></b><br>\n";
fromegame
Code:
PHP sent this statement to MySQL: SELECT * FROM users WHERE 'id' = '57' AND 'key' = '2d76471e6f56a63e6f0105dd92db4254'
hexkid
fromegame wrote:
Code:
PHP sent this statement to MySQL: SELECT * FROM users WHERE 'id' = '57' AND 'key' = '2d76471e6f56a63e6f0105dd92db4254'
And what happened when you sent that same statement to MySQL?
I bet it said there were 0 (zero) rows returned.

"Yes. Why?" I hear you ask Smile

Well 'id' = '57' or 'key' = '2d7...' will *NEVER* match!
You're comparing 'id' with '57', not the contents of the column named 'id' with the value '57'.
Use one of these, your choice (listed in order of my preference)
Code:
select ... where id=57 and key='2d7...'
select ... where id = 57 and key = '2d7...'
select ... where id=57 and key="2d7..."
select ... where id='57' and key='2d7...'
select ... where id="57" and key="2d7..."
select ... where id=57 and `key`='2d7...'
select ... where `id`=57 and key='2d7...'
select ... where `id`=57 and `key`='2d7...'


Notice that the quotes surrounding id and key are backquotes or ticks, not single quotes.
fromegame
YEAAAAAAAH, it finally works, thank you hexkid!!! Very Happy
Related topics
Which is your favourite weblog Script?
Chat script
Script Upload (obiefileman)
script backup database
Script run background
Can someone make me a php script?
target = _parent redirect script?
Bookmark Script:
Some Script Show
Image transparency script
A script for Loading
Set As Home Page Script (IE Only)
Activation and approval !!
150 frih$ if you make me a login script with....
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.