zombie Posted January 16, 2012 Share Posted January 16, 2012 I've been following a tutorial on making a fairly simple login script. It's my first time really playing with php and sticking with it and so far so good. But I can't figure this one out. It's using a fairly simple email activation thing but the activation link isn't working. It echos that it was successful, but the database hasn't been updated at all. I double checked and the ID and activation code are both correct, but the 'group' is still set to 0. Help? <?php $title = "Account Activation"; require_once('header.php'); $id = $_GET['id']; $code = $_GET['code']; if ($id&&$code) { $check = mysql_query("SELECT * FROM users WHERE id='$id' AND actcode='$code'"); $checknum = mysql_num_rows($check); if ($checknum==1) { //activate the account $activate = mysql_query("UPDATE users SET group='1' WHERE id='$id'"); echo("Your account is activated. You may now log in."); require_once "footer.php"; } else echo("Invalid ID or activation code."); require_once "footer.php"; die(); } else echo("Data Missing!"); require_once "footer.php"; die(); require_once "footer.php"; ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 16, 2012 Share Posted January 16, 2012 If it is getting to the successful message then the first query is getting run successfully. So, if the record is not getting updated then the 2nd query is likely failing and you aren't checking if it failed or not. But, the logic you have is flawed anyway. instead of running one query to check if the record exists and another to update the record, just run the query to update the record. Then check if any records were updated. This fixes some of the logic and should tell you what the error is. <?php //Prepriocess GET data $id = isset($_GET['id']) ? intval($_GET['id']) : false; $code = isset($_GET['code']) ? mysql_real_escape_string($_GET['code']) : false; if (!$id || !$code) { $output = "ID and/or Activation code not sent!"; } else { $query = "UPDATE users SET group='1' WHERE id='$id' AND actcode='$code'"; $result = mysql_query($query); if(!$result) { $output = "Error running query"; //This line for debugging only $output .= "<br>Query: {$query}<br>Error:<br>" . mysql_error(); } elseif(mysql_affected_rows()==0) { $output = "Invalid ID or activation code."; } else { $output = "Your account is activated. You may now log in."; } } $title = "Account Activation"; require_once('header.php'); echo $output; require_once "footer.php"; ?> 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.