jwk811 Posted October 23, 2006 Share Posted October 23, 2006 im getting a T_ELSE error so im assuming that you cant do it... what do you think.. heres my script...[code]<?/* Account activation script */// Get database connectioninclude ( './db.php' );// Create variables from URL.// first check if it's already been activated$sql = mysql_query ( "SELECT COUNT(*) AS total FROM users WHERE userid = '" . mysql_real_escape_string ( $_REQUEST['id'] ) . "' AND password = '" . mysql_real_escape_string ( $_REQUEST['code'] ) . "' AND activated = 1" ) or die ( 'Query Error: ' . mysql_error );$found = mysql_fetch_assoc ( $sql );if ( $found['total'] == 0 ){ $sql = mysql_query ( "UPDATE users SET activated = 1 WHERE userid = '" . mysql_real_escape_string ( $_REQUEST['id'] ) . "' AND password = '" . mysql_real_escape_string ( $_REQUEST['code'] ) . "'" ) or die ( 'Query Error: ' . mysql_error ); if ( mysql_affected_rows ( $sql ) == 0 ) { die(mysql_error()); } { echo "<strong><font color='red'>Your account could not be activated, no user found by that id or password!</font></strong>"; } else { echo "<strong>Your account has been activated!</strong> You may login below!<br />"; include ( './login.php' ); }}else{ echo "<strong>You have already activated your account!</strong> You may login below!<br />"; include ( './login.php' );}?>[/code] Quote Link to comment Share on other sites More sharing options...
Design Posted October 23, 2006 Share Posted October 23, 2006 You and I are both in the same boat, and I think the solution lies within either the Case or Switch functions, I'm going to look and see if w3schools.com has some reference to this, so I'll let you know if I find anything. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted October 23, 2006 Share Posted October 23, 2006 You can't use die and then output info for the user!!!That script is simply not structureed well so you have missing closing tags etc etc.Learn to indent you code more effectively - it will help you spot erros.This is what I think you trying to do (I have removed the die(mysql_error()); line as it is not needed - if there were and error you'd never get to that line..)[code]if ( $found['total'] == 0 ){ $sql = mysql_query ( "UPDATE users SET activated = 1 WHERE userid = '" . mysql_real_escape_string ( $_REQUEST['id'] ) . "' AND password = '" . mysql_real_escape_string ( $_REQUEST['code'] ) . "'" ) or die ( 'Query Error: ' . mysql_error ); if ( mysql_affected_rows ( $sql ) == 0 ) { echo "<strong><font color='red'>Your account could not be activated, no user found by that id or password!</font></strong>"; } else { echo "<strong>Your account has been activated!</strong> You may login below!<br />"; include ( './login.php' ); }}else{ echo "<strong>You have already activated your account!</strong> You may login below!<br />"; include ( './login.php' );}[/code] Quote Link to comment Share on other sites More sharing options...
Design Posted October 23, 2006 Share Posted October 23, 2006 Okay, i'm not 100% sure, but I think you could pull it off using If().... elseif().... elseif().... else() Quote Link to comment Share on other sites More sharing options...
jwk811 Posted October 23, 2006 Author Share Posted October 23, 2006 thanks design.. ill mess around with that and see if i can get it to work.. i think your right.. first im gonna see what toon meant with that script and try to get this to work.. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted October 23, 2006 Share Posted October 23, 2006 No his structure is correct try to avoid comparing completely different elemenst in an else if statement - if only to avoid confusion.if you are looking at one compariosn with many potential values that control code flow then use the switch statement but in this case it is not necessary Quote Link to comment Share on other sites More sharing options...
jwk811 Posted October 23, 2006 Author Share Posted October 23, 2006 nope im still getting the same error with your script toon.. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted October 23, 2006 Share Posted October 23, 2006 in the query line...you are missing '()' after mysql_error Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted October 23, 2006 Share Posted October 23, 2006 This is how I would have done it - you shoudl find it a bit easier to read....[code]<?phpif ( $found['total'] == 0 ){ $sql = " UPDATE users SET activated = 1 WHERE userid = '" . mysql_real_escape_string ( $_REQUEST['id'] ) . "' AND password = '" . mysql_real_escape_string ( $_REQUEST['code'] ) . "' "; $sql = mysql_query($qry) or die ( 'Query Error: ' . mysql_error()); if ( mysql_affected_rows ( $sql ) == 0 ) {?> <strong><font color="red">Your account could not be activated, no user found by that id or password!</font></strong>";<?php } else {?> <strong>Your account has been activated!</strong> You may login below!<br />";<?php include ( './login.php' ); }}else{?> <strong>You have already activated your account!</strong> You may login below!<br />";<?php include ( './login.php' );}?>[/code]well if it didn't bugger up teh tabs so much ;) Quote Link to comment Share on other sites More sharing options...
jwk811 Posted October 23, 2006 Author Share Posted October 23, 2006 thanks man.. i used your code and this came up... Query Error: Query was emptywould you know what that means and how to fix it? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted October 23, 2006 Share Posted October 23, 2006 echo the query to teh screen and check it in phpmyadmin or something - see if it returns any rows or highligths any specific error. Quote Link to comment Share on other sites More sharing options...
jwk811 Posted October 23, 2006 Author Share Posted October 23, 2006 in phpmyadmin its normal so i dont know whats wrong with it Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.