|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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'; } ?> |
|
#2
|
|||
|
|||
|
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:
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! |
|
#3
|
|||
|
|||
|
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!'; } ?> |
|
#4
|
|||
|
|||
|
The wrong parameter count is because of your line:
PHP Code:
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? |
|
#5
|
|||
|
|||
|
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!'; } ?> |
|
#6
|
|||
|
|||
|
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. |
|
#7
|
|||
|
|||
|
Quote:
yes that's exactly what i'm doing |
|
#8
|
|||
|
|||
|
Can you post the exact link you're using?
|
|
#9
|
|||
|
|||
|
My code above had a slight mistake, try this code, i have also added some validation
PHP Code:
Also please use php tags on any code you type, use [ PHP ] and [ /PHP ] (without spaces) to surround your code. |
|
#10
|
|||
|
|||
|
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:
|
|
#11
|
|||
|
|||
|
My mistake
PHP Code:
|
|
#12
|
|||
|
|||
|
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:
|
|
#13
|
|||
|
|||
|
Ok so using the following code works for me: PHP Code:
|