PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 7th, 2005, 11:19 AM
webNerd webNerd is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 17 webNerd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 22 m 43 sec
Reputation Power: 0
Question 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';
}

?>

Reply With Quote
  #2  
Old February 7th, 2005, 02:33 PM
mattp23 mattp23 is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: UK
Posts: 82 mattp23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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 == )
  {
    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!

Reply With Quote
  #3  
Old February 8th, 2005, 07:03 AM
webNerd webNerd is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 17 webNerd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 22 m 43 sec
Reputation Power: 0
Question 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!';
}
?>

Reply With Quote
  #4  
Old February 8th, 2005, 07:41 AM
mattp23 mattp23 is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: UK
Posts: 82 mattp23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #5  
Old February 8th, 2005, 09:58 AM
webNerd webNerd is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 17 webNerd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 22 m 43 sec
Reputation Power: 0
Question 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!';
}
?>

Reply With Quote
  #6  
Old February 8th, 2005, 11:43 AM
mattp23 mattp23 is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: UK
Posts: 82 mattp23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #7  
Old February 9th, 2005, 01:15 PM
webNerd webNerd is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 17 webNerd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 22 m 43 sec
Reputation Power: 0
Question

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

Reply With Quote
  #8  
Old February 9th, 2005, 03:00 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 14
Can you post the exact link you're using?

Reply With Quote
  #9  
Old February 10th, 2005, 04:50 AM
mattp23 mattp23 is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: UK
Posts: 82 mattp23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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 )
  {
    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.

Reply With Quote
  #10  
Old February 12th, 2005, 10:46 PM
webNerd webNerd is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 17 webNerd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 22 m 43 sec
Reputation Power: 0
Question

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 )
  {
    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.

Reply With Quote
  #11  
Old February 14th, 2005, 10:55 AM
mattp23 mattp23 is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: UK
Posts: 82 mattp23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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 == '' 

Reply With Quote
  #12  
Old February 15th, 2005, 01:30 AM
webNerd webNerd is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 17 webNerd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 22 m 43 sec
Reputation Power: 0
Question

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 == '' )

Reply With Quote
  #13  
Old February 15th, 2005, 04:34 AM
mattp23 mattp23 is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: UK
Posts: 82 mattp23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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 )
  {
    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.

Reply With Quote
  #14  
Old February 16th, 2005, 06:29 PM
webNerd webNerd is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 17 webNerd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 22 m 43 sec
Reputation Power: 0
Smile 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!

Reply With Quote
  #15  
Old February 17th, 2005, 08:49 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,886 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > My activate.php won't activate | mysql_query("UPDATE


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap