yobo Posted March 10, 2007 Share Posted March 10, 2007 hey all i have a user registration script and it creats the user name and sends the user the activation link now problem there but for some reasson my script does not want to update the status of the user in the database at the moment by activated colunm default value is no and well it does not want to update to yes here is my activation script <?php include("config.php"); // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // select the database mysql_select_db($database) or die ("Could not select database because ".mysql_error()); /* In the url we should have &code={characters} in it, this is the users activation code. We use the $_GET function in order to pull it out of the url into a variable. We use the if statement in this to make sure that we have it here, if it we dont, then we can show a message that it's not there. */ if($actcode = $_GET['code']){ //Check to see if it's not empty if($actcode != NULL){ /* Now we got the activation code they came here with, we need to select from the database where the activation code equals any from the table. */ $acti = "SELECT activated FROM users WHERE actcode = '$actcode'"; $acti = mysql_query($acti); //We want to find out if there are any rows with this, if so, it should come up with 1, if not, then 0. $actin = mysql_num_rows($acti); //Using the if statement, we can see if the activation is correct, since it should return higher than 0. if($actin > 0){ //We edit the table to make activated in yes. $update = "UPDATE users SET activated='yes' WHERE actcode='$code'"; $update = mysql_query($update) or die(mysql_error()); echo("You have successfully activated your account. You may not log in. Thank you."); }else{ //If it was 0 rows echo("Activation code is incorrect."); } }else{ //if code was blank echo("Code is blank."); } }else{ echo("No activation code."); } ?> and my user register script <?php include("config.php"); $username = $_POST['username']; $password = $_POST['password']; $email = $_POST['email']; $name = $_POST['name']; $website = $_POST['website']; $alphanum = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; //Alphabet and numbers $actcode = substr(str_shuffle($alphanum), 0, 7); //Take out strings with the shuffled alphanum variable, from the start to 7 characters. // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // select the database mysql_select_db($database) or die ("Could not select database because ".mysql_error()); // check if the username is taken $check = "SELECT userid FROM users WHERE username = '".$_POST['username']."';"; $qry = mysql_query($check) or die ("Could not match data because ".mysql_error()); $num_rows = mysql_num_rows($qry); if ($num_rows != 0) { echo "Sorry, there the username $username is already taken.<br>"; echo "<a href=signup.php>Try again</a>"; } // insert the data $insert = "INSERT INTO users SET username='$username', password='$password', email='$email', name='$name', website='$website', actcode='$actcode'"; if (@mysql_query($insert)) { echo '<p>New DJ Added!</p>'; } else { echo "<p>Database Error - New DJ not Added " . mysql_error() . '</p>'; } //send email $to = "$email"; $re = "Activate Account"; $headers = "From: [email protected] rn"; $msg = "This is an automated message, please do not reply. You are receiving this email because you or someone else has registered to our site with this email. If you think this is a mistake then please contact the administrator on [email protected] Thank you for registering with address.com - but before you can log in you will need to activate your account, you can do this by clicking the link below. http://localhost/phpbb3hacks/activate.php?code=".$actcode." address.com Team."; if(mail($to,$re,$msg, $headers)){ echo("Thank you for registering, but before you can log in you need to activate your account. Please check your emails."); }else{ echo("An error occured while sending an email. Please contact the site administrator."); } ?> thanks guys Please use the code tags ( ) when posting code in posts. I have modified your post - wildteen88 Link to comment https://forums.phpfreaks.com/topic/42115-database-not-updating/ Share on other sites More sharing options...
aniesh82 Posted March 10, 2007 Share Posted March 10, 2007 Hello The updation is by the following stmt: if($actin > 0){ //We edit the table to make activated in yes. $update = "UPDATE users SET activated='yes' WHERE actcode='$code'"; $update = mysql_query($update) or die(mysql_error()); echo("You have successfully activated your account. You may not log in. Thank you."); } Do you want to stop updating your table ? If so , please make a comment on the bellow line: ## $update = mysql_query($update) or die(mysql_error()); Regards Aniesh Joseph Link to comment https://forums.phpfreaks.com/topic/42115-database-not-updating/#findComment-204273 Share on other sites More sharing options...
yobo Posted March 10, 2007 Author Share Posted March 10, 2007 Hello The updation is by the following stmt: if($actin > 0){ //We edit the table to make activated in yes. $update = "UPDATE users SET activated='yes' WHERE actcode='$code'"; $update = mysql_query($update) or die(mysql_error()); echo("You have successfully activated your account. You may not log in. Thank you."); } Do you want to stop updating your table ? If so , please make a comment on the bellow line: ## $update = mysql_query($update) or die(mysql_error()); Regards Aniesh Joseph ok thats the same as i have in my exsisting code? Link to comment https://forums.phpfreaks.com/topic/42115-database-not-updating/#findComment-204285 Share on other sites More sharing options...
paul2463 Posted March 10, 2007 Share Posted March 10, 2007 is the original script throwing an error with the update code or is just not running?? in other word do you get the "You have successfully activated your account. You may not log in. Thank you" but no update or do you not get anything? Link to comment https://forums.phpfreaks.com/topic/42115-database-not-updating/#findComment-204301 Share on other sites More sharing options...
paul2463 Posted March 10, 2007 Share Posted March 10, 2007 before you answer my last question I will ask another..in this line $update = "UPDATE users SET activated='yes' WHERE actcode='$code'"; where is $code set ??? in this line $acti = "SELECT activated FROM users WHERE actcode = '$actcode'"; you are searching for entries with $actcode should not your update query look like this then? $update = "UPDATE users SET activated='yes' WHERE actcode='$actcode'"; Link to comment https://forums.phpfreaks.com/topic/42115-database-not-updating/#findComment-204303 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.