|
 |
|
Dev Articles Community Forums
> Programming
> PHP Development
|
My activate.php won't activate | mysql_query("UPDATE
Discuss My activate.php won't activate | mysql_query("UPDATE in the PHP Development forum on Dev Articles. My activate.php won't activate | mysql_query("UPDATE PHP Development forum to discuss anything related to developing applications in PHP. Topics include architecture, coding standards, and debugging methods.
|
|
 |
|
|
|

Dev Articles Community Forums Sponsor:
|
|

February 7th, 2005, 10:19 AM
|
Registered User
|
|
Join Date: Feb 2005
Posts: 17
Time spent in forums: 11 h 22 m 43 sec
Reputation Power: 0
|
|
My activate.php won't activate | mysql_query("UPDATE
i'm working from this tutorial:
http://www.devarticles.com/c/a/PHP/Creating-a-Membership-System/2/
i finally got my register page working. now it generates a password for my users. but now my activation page that suppose to activate the username and password don't activate nothing although it says it did. making the username and password useless for the login page. for mysql_query i tried it with UPDATE and SELECT and it still give me problems.
2 attempts have been made
below are both codes i tried:
this was my 1st attempt which is from the tutorial:
<?php
/* connect to database */
include 'db.php';
/* create variables from URL */
$id = $_REQUEST['id'];
$code = $_REQUEST['code'];
/* Check my Query and activate the account */
$sql = mysql_query("UPDATE users SET activated='1' WHERE id='$id' AND password='$code'") or die (mysql_error());
/* Double checks the Answer and activate the account */
$sql_doublecheck = mysql_query("SELECT * FROM users WHERE id='$id' AND password='$code' AND activated='1'");
$doublecheck = mysql_num_rows($sql_doublecheck);
if($doublecheck == 0) {
echo "<strong><font color=red> Your account could not be activated!</font></strong><p />";
include 'register.php';
} elseif ($doublecheck > 0) {
echo "<strong>Your account has been activated!</strong><p />";
include 'login.php';
}
?>
the 2nd attempt
<?php
/* connect to database */
include 'db.php';
/* create variables from URL */
$id = $_REQUEST['id'];
$code = $_REQUEST['code'];
/* Check my Query and activate the account */
$sql = mysql_query("UPDATE users SET activated='1' WHERE id='$id' AND password='$code'") or die (mysql_error());
/* Double checks the Answer and activate the account */
if (mysql_affected_rows() > 0) {
echo "<strong><font color=red> Your account could not be activated!</font></strong><p />";
include 'register.php';
} else {
echo "<strong>Your account has been activated!</strong><p />";
include 'login.php';
}
?>
|

February 7th, 2005, 01:33 PM
|
Moderated
|
|
Join Date: Oct 2003
Location: UK
Posts: 82
Time spent in forums: 5 h 43 m 44 sec
Reputation Power: 15
|
|
First off I would suggest trying $_GET['id'] and $_GET['code'] rather than request. (Assuming that the page is called via something like activate.php?id=x%code=xxx )
Then try putting some debugging messages in
PHP Code:
<?php
include 'db.php';
$id = $_GET['id'];
$code = $_GET['code'];
echo "DEBUG: id = $id and code = $code.<br />";
$activate_sql = "UPDATE users SET activated='1' WHERE id='$id' AND password='$code'";
echo "DEBUG: activate_sql = $activate_sql.<br />";
mysql_query( $activate_sql )
or die( mysql_error() );
$check_sql = "SELECT * FROM users WHERE id='$id' AND password='$code' AND activated='1'";
echo "DEBUG: check_sql = $check_sql.<br />";
$result = mysql_query( $check_sql );
$num = mysql_num_rows( $result );
if( $num == 0 )
{
echo 'Done<br />';
}
else
{
echo 'Failed<br />';
}
?>
Also please note that if the 'activated' column is an integer then the sql should look like:
....SET activated=1 WHERE...
not
...SET activated='1' WHERE...
and the same for 'id'.
Let us know what the output is
__________________
http://www.phptutorials.cjb.net. go on, give it a click!
|

February 8th, 2005, 06:03 AM
|
Registered User
|
|
Join Date: Feb 2005
Posts: 17
Time spent in forums: 11 h 22 m 43 sec
Reputation Power: 0
|
|
My activate.php won't activate | mysql_query("UPDATE
i used your exact code and i didn't get any errors but it still didn't activate the user user id and password in my mysql database.
so i tried to script someting else and i still got nothing. what can i do to get it to activate the user account.
when a user click on this link www.company.com/activate.php?id&code
and it will post to this php file
this code i'm using now and i getting this error with it
Warning: Wrong parameter count for mysql_num_rows() in www.company.com/html/login/activate.php on line 11
.
<?php
/* connect to database */
include 'db.php';
/* create variables from URL */
$id = $_GET['id'];
$code = $_GET['code'];
/* Check my Query and activate the account */
$activate = mysql_query("UPDATE users SET activated='1' WHERE id='$id' AND password='$code' AND activated='0'") or die (mysql_error());;
$activate_sql = mysql_query("SELECT * FROM users WHERE id='$id' AND password='$code'");
$answer = mysql_query($activate_sql);
if (mysql_num_rows() > 0) {
echo 'Activated!';
} else {
echo 'Not Activated!';
}
?>
|

February 8th, 2005, 06:41 AM
|
Moderated
|
|
Join Date: Oct 2003
Location: UK
Posts: 82
Time spent in forums: 5 h 43 m 44 sec
Reputation Power: 15
|
|
The wrong parameter count is because of your line:
PHP Code:
if (mysql_num_rows() > 0) {
# should be
if (mysql_num_rows( $answer ) > 0) {
I think thats right.
When you used my code above what output did you get?
It should have outputted a bunch of sql, can you please post that code?
|

February 8th, 2005, 08:58 AM
|
Registered User
|
|
Join Date: Feb 2005
Posts: 17
Time spent in forums: 11 h 22 m 43 sec
Reputation Power: 0
|
|
My activate.php won't activate | mysql_query("UPDATE
here you go
when i use your code, i get the output below and it list the specific info. but your code still don't change activated to '1' from '0' in mysql database. the user can't login until activated is changed to '1'
DEBUG: id = and code = .
DEBUG: activate_sql = UPDATE dbUsers SET activated='1' WHERE id='' AND password=''.
DEBUG: check_sql = SELECT * FROM dbUsers WHERE id='' AND password='' AND activated='1'.
Done
<?php
include 'db.php';
$id = $_GET['id'];
$code = $_GET['code'];
echo "DEBUG: id = $id and code = $code.<br />";
$activate_sql = "UPDATE users SET activated='1' WHERE id='$id' AND password='$code'";
echo "DEBUG: activate_sql = $activate_sql.<br />";
mysql_query( $activate_sql )
or die( mysql_error() );
$check_sql = "SELECT * FROM users WHERE id='$id' AND password='$code' AND activated='1'";
echo "DEBUG: check_sql = $check_sql.<br />";
$result = mysql_query( $check_sql );
$num = mysql_num_rows( $result );
if( $num == 0 )
{
echo 'Done<br />';
}
else
{
echo 'Failed<br />';
}
?>
even after i change the mysql_num_rows thing in my 2nd code i still get this error
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /www/html/login/activate.php on line 11
<?php
/* connect to database */
include 'dbConfig.php';
/* create variables from URL */
$id = $_REQUEST['id'];
$code = $_REQUEST['code'];
/* Check my Query and activate the account */
$activate = mysql_query("UPDATE dbUsers SET activated='1' WHERE id='$id' AND password='$code' AND activated='0'") or die (mysql_error());
$activate_sql = mysql_query("SELECT * FROM dbUsers WHERE id='$id' AND password='$code'");
$answer = mysql_query($activate_sql);
if (mysql_num_rows($answer) > 0) {
echo 'Activated!';
} else {
echo 'Not Activated!';
}
?>
|

February 8th, 2005, 10:43 AM
|
Moderated
|
|
Join Date: Oct 2003
Location: UK
Posts: 82
Time spent in forums: 5 h 43 m 44 sec
Reputation Power: 15
|
|
Are you setting id and code in the url?
If you are trying to activate user id 3 with code xyz the url would be
activate.php?id=3&code=xyz, change the id and code as required.
|

February 9th, 2005, 12:15 PM
|
Registered User
|
|
Join Date: Feb 2005
Posts: 17
Time spent in forums: 11 h 22 m 43 sec
Reputation Power: 0
|
|
Quote:
Originally Posted by mattp23
Are you setting id and code in the url?
If you are trying to activate user id 3 with code xyz the url would be
activate.php?id=3&code=xyz, change the id and code as required.
|
yes that's exactly what i'm doing
|

February 9th, 2005, 02:00 PM
|
My beat is correct.
|
|
Join Date: Dec 2004
Posts: 339

Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 14
|
|
Can you post the exact link you're using?
|

February 10th, 2005, 03:50 AM
|
Moderated
|
|
Join Date: Oct 2003
Location: UK
Posts: 82
Time spent in forums: 5 h 43 m 44 sec
Reputation Power: 15
|
|
My code above had a slight mistake, try this code, i have also added some validation
PHP Code:
<?php
include 'db.php';
$id = isSet( $_GET['id'] ) ? $_GET['id'] : '';
$code = isSet( $_GET['code'] ) ? $_GET['code'] : '';
if( $id = '' )
{
die( 'You have not set id or it is blank. Cannot continue.' );
}
if( $code = '' )
{
die( 'You have not set code or it is blank. Cannot contine.' );
}
echo "DEBUG: id = $id and code = $code.<br />";
$activate_sql = "UPDATE users SET activated='1' WHERE id='$id' AND password='$code'";
echo "DEBUG: activate_sql = $activate_sql.<br />";
mysql_query( $activate_sql )
or die( mysql_error() );
$check_sql = "SELECT * FROM users WHERE id='$id' AND password='$code' AND activated='1'";
echo "DEBUG: check_sql = $check_sql.<br />";
$result = mysql_query( $check_sql );
$num = mysql_num_rows( $result );
if( $num > 0 )
{
echo 'Done<br />';
}
else
{
echo 'Failed<br />';
}
?>
Also please use php tags on any code you type, use [ PHP ] and [ /PHP ] (without spaces) to surround your code.
|

February 12th, 2005, 09:46 PM
|
Registered User
|
|
Join Date: Feb 2005
Posts: 17
Time spent in forums: 11 h 22 m 43 sec
Reputation Power: 0
|
|
when i used this last code you gave me, i get this error:
Parse error: parse error, unexpected T_VARIABLE in /www/html/login/activate.php on line 9
Quote:
Originally Posted by mattp23
My code above had a slight mistake, try this code, i have also added some validation
PHP Code:
<?php
include 'db.php';
$id = isSet( $_GET['id'] ) ? $_GET['id'] : '';
$code = isSet( $_GET['code'] ) ? $_GET['code'] : '';
if( $id = '' )
{
die( 'You have not set id or it is blank. Cannot continue.' );
}
if( $code = '' )
{
die( 'You have not set code or it is blank. Cannot contine.' );
}
echo "DEBUG: id = $id and code = $code.<br />";
$activate_sql = "UPDATE users SET activated='1' WHERE id='$id' AND password='$code'";
echo "DEBUG: activate_sql = $activate_sql.<br />";
mysql_query( $activate_sql )
or die( mysql_error() );
$check_sql = "SELECT * FROM users WHERE id='$id' AND password='$code' AND activated='1'";
echo "DEBUG: check_sql = $check_sql.<br />";
$result = mysql_query( $check_sql );
$num = mysql_num_rows( $result );
if( $num > 0 )
{
echo 'Done<br />';
}
else
{
echo 'Failed<br />';
}
?>
Also please use php tags on any code you type, use [ PHP ] and [ /PHP ] (without spaces) to surround your code.
|
|

February 14th, 2005, 09:55 AM
|
Moderated
|
|
Join Date: Oct 2003
Location: UK
Posts: 82
Time spent in forums: 5 h 43 m 44 sec
Reputation Power: 15
|
|
My mistake
PHP Code:
if( $id = '' )
# should be
if( $id == '' )
# and
if( $code = '' )
#should be
if( $code == '' )
|

February 15th, 2005, 12:30 AM
|
Registered User
|
|
Join Date: Feb 2005
Posts: 17
Time spent in forums: 11 h 22 m 43 sec
Reputation Power: 0
|
|
even with the new changes, i'm still getting the error just on line 8 instead of line 9
Parse error: parse error, unexpected T_VARIABLE in /home/virtual/site20/fst/var/www/html/manage/activate.php on line 8
i even change isSet() to isset()
what am i doing wrong?
Quote:
Originally Posted by mattp23
My mistake
[PHP]
if( $id = '' )
# should be
if( $id == '' )
# and
if( $code = '' )
#should be
if( $code == '' )
|
|

February 15th, 2005, 03:34 AM
|
Moderated
|
|
Join Date: Oct 2003
Location: UK
Posts: 82
Time spent in forums: 5 h 43 m 44 sec
Reputation Power: 15
|
|
Ok so using the following code works for me:
PHP Code:
<?php
include 'db.php';
$id = isSet( $_GET['id'] ) ? $_GET['id'] : '';
$code = isSet( $_GET['code'] ) ? $_GET['code'] : '';
if( $id == '' )
{
die( 'You have not set id or it is blank. Cannot continue.' );
}
if( $code == '' )
{
die( 'You have not set code or it is blank. Cannot contine.' );
}
echo "DEBUG: id = $id and code = $code.<br />";
$activate_sql = "UPDATE users SET activated='1' WHERE id='$id' AND password='$code'";
echo "DEBUG: activate_sql = $activate_sql.<br />";
mysql_query( $activate_sql )
or die( mysql_error() );
$check_sql = "SELECT * FROM users WHERE id='$id' AND password='$code' AND activated='1'";
echo "DEBUG: check_sql = $check_sql.<br />";
$result = mysql_query( $check_sql );
$num = mysql_num_rows( $result );
if( $num > 0 )
{
echo 'Done<br />';
}
else
{
echo 'Failed<br />';
}
?>
I don't have a db.php so i took that line out (obvisouly none of the sql works for me, but that is to be exprected).
Maybe there is a problem with your db.php?
I cant get the problem you are reporting, check your code is the same as mine. What version of php are you running?
You could try changing die( '...' ) to exit( '...' ) but that shouldn't matter.
|

February 16th, 2005, 05:29 PM
|
Registered User
|
|
Join Date: Feb 2005
Posts: 17
Time spent in forums: 11 h 22 m 43 sec
Reputation Power: 0
|
|
My activate.php won't activate | mysql_query("UPDATE Reply to Thread
i finally got it to work! i used the original code from the tutorial but instead of using $_REQUEST[] or $_GET[], i ended up using $HTTP_GET_VARS[] and $HTTP_POST_VARS[] for my activate and register php files.
my hosting is using the version 4.3.10 for php. could anyone explain what the difference in $_REQUEST[] or $_GET[], $HTTP_GET_VARS[] and why one work while the other two didn't. don't get me wrong, i'm glad it works but i want to make sure i learned my lesson.
thanks again guys for the help!
|

February 17th, 2005, 07:49 AM
|
 |
I'm Internet Famous
|
|
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,886
 
Time spent in forums: 1 Week 16 h 19 m 35 sec
Reputation Power: 18
|
|
Unexpected T_VARIABLE generally means your code is missing a semi-colon...
check the line above the line that's reporting the error
|
Developer Shed Advertisers and Affiliates
Thread Tools |
Search this Thread |
|
|
Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|