Problems with email activation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Blaade
Forum Commoner
Posts: 29
Joined: Tue Feb 28, 2012 8:44 am

Re: Problems with email activation

Post by Blaade »

Unknown column 'Blade' in 'where clause'

Maybe i need to pray or something to make it work :)
temidayo
Forum Contributor
Posts: 109
Joined: Fri May 23, 2008 6:17 am
Location: Nigeria

Re: Problems with email activation

Post by temidayo »

Now Try this:

Code: Select all

<?php
session_start();
$mysql_server = 'localhost';
$mysql_username = 'username';
$mysql_password = 'password';
$mysql_database = 'database';
$mysql_table = 'USERS';
$success_page = './thank_you_page.html';
$error_message = "";
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['form_name'] == 'signupform')
{
    $newusername = $_POST['username'];
    $newemail = $_POST['email'];
    $newpassword = $_POST['password'];
    $confirmpassword = $_POST['confirmpassword'];
    $website = $_SERVER['HTTP_HOST'];
    $script = $_SERVER['SCRIPT_NAME'];
    $timestamp = time();
    $code = md5($website . $timestamp . rand(100000, 999999));
    if ($newpassword != $confirmpassword)
    {
        $error_message = 'Password and Confirm Password are not the same!';
    }
    else
    if (!ereg("^[A-Za-z][a-z_.]{3,25}[a-z0-9]$", $newusername))
    {
        $error_message = 'Username is not valid, please check and try again!';
    }
    else
    if (!ereg("^[a-z0-9]{5,50}$", $newpassword))
    {
        $error_message = 'Password is not valid, please check and try again!';
    }
    else
    if (!ereg("^[A-Za-z0-9\.|-|_]*[@]{1}[A-Za-z0-9\.|-|_]*[.]{1}[a-z]{2,5}$", $newemail))
    {
        $error_message = 'Email is not a valid email address. Please check and try again.';
    }
    if (empty($error_message))
    {
        $db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
        if (!$db)
        {
            die('Failed to connect to database server!<br>' . mysql_error());
        }
        mysql_select_db($mysql_database, $db) or die('Failed to select database<br>' . mysql_error());
        $sql = "SELECT username FROM " . $mysql_table . " WHERE username = '" . $newusername . "'";
        $result = mysql_query($sql, $db);
        if ($data = mysql_fetch_array($result))
        {
            $error_message = 'Username already used. Please select another username.';
        }
    }
    if (empty($error_message))
    {
        $crypt_pass = md5($newpassword);
        $newusername = mysql_real_escape_string($newusername);
        $newemail = mysql_real_escape_string($newemail);
        $newfullname = mysql_real_escape_string($newfullname);
        $sql = "INSERT `" . $mysql_table . "` (`username`, `password`, `email`, `active`, `code`) VALUES ('$newusername', '$crypt_pass', '$newemail', '0', '$code')";
        $result = mysql_query($sql, $db);
        mysql_close($db);
        $subject = 'Email confirmation';
        $message = 'Hi!Thanks for creating an account on our site. Click the link below to confirm your email address:';
        $message .= "\r\nUsername: ";
        $message .= $newusername;
        $message .= "\r\nPassword: ";
        $message .= $newpassword;
        $message .= "\r\n";
        $message .= "\r\nhttp://" . $website . $script . "?user=" . $newusername . "&code=$code";
        $message .= "\r\n\r\nThis is an automated message - please do not reply";
        $header = "From: webmaster@myhoo22.com" . "\r\n";
        $header .= "Reply-To: webmaster@myhoo22.com" . "\r\n";
        $header .= "MIME-Version: 1.0" . "\r\n";
        $header .= "Content-Type: text/plain; charset=utf-8" . "\r\n";
        $header .= "Content-Transfer-Encoding: 8bit" . "\r\n";
        $header .= "X-Mailer: PHP v" . phpversion();
        mail($newemail, $subject, $message, $header);
        header('Location: ' . $success_page);
        exit;
    }
}
else
if (isset($_GET['code']) && isset($_GET['user']))
{
    $db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
    if (!$db)
    {
        die('Failed to connect to database server!<br>' . mysql_error());
    }
    mysql_select_db($mysql_database, $db) or die('Failed to select database<br>' . mysql_error());
    // I'm assuming the column id exists. If not, use your primary key in place of id
    $sql = "SELECT username FROM " . $mysql_table . " WHERE username = '" . $_GET['user'] . "' AND code = '" . $_GET['code'] . "'";
     $result = mysql_query($sql) or die(mysql_error());    
/*list($username) = mysql_fetch_row($result);
    if (!$username)
    {
        die("There was an error in the following sql statement:<hr>$sql<br />" . mysql_error());
    }
*/   
 // User has been found, so we'll activate the account
    $query = "UPDATE {$mysql_table} SET active = '1' WHERE username = '".$_GET['user']."'";
    mysql_query($query) or die('UPDATE ERROR: '.mysql_error());
    header("refresh:5;url=log_in.php");
    echo 'Your user account was succesfully activated. You\'ll be redirected in about 5 secs. If not, click <a href="log_in.php">here</a>.';
    exit;
}
?>
 
Blaade
Forum Commoner
Posts: 29
Joined: Tue Feb 28, 2012 8:44 am

Re: Problems with email activation

Post by Blaade »

Man...i don't know what to say...Thanks a lot and god bless you! If it wasn't for you i would be stuck for life ii think. After 3 days of :banghead: you made me happy:D Thank you so much. Think everything it's in order now.
And one last thing if i got your attention, maybe you know. I made a forum and there is a text area named About me. When someone writes words with " ' " (Example: It's, he's....) and submits....on the other page where the form is submitted the words appear like this: It\'s, he\'s, I\'m...Maybe you know the problem because i don't know what to search for, on the internet...
Thank you very much again!
temidayo
Forum Contributor
Posts: 109
Joined: Fri May 23, 2008 6:17 am
Location: Nigeria

Re: Problems with email activation

Post by temidayo »

Blaade wrote:Man...i don't know what to say...Thanks a lot and god bless you! If it wasn't for you i would be stuck for life ii think. After 3 days of :banghead: you made me happy:D Thank you so much. Think everything it's in order now.
You are welcome.
Blaade wrote: And one last thing if i got your attention, maybe you know. I made a forum and there is a text area named About me. When someone writes words with " ' " (Example: It's, he's....) and submits....on the other page where the form is submitted the words appear like this: It\'s, he\'s, I\'m...Maybe you know the problem because i don't know what to search for, on the internet...
Thank you very much again!
What you are experiencing is the action of magic quotes. You can remove the effect by running this function

Code: Select all

function my_strip_slashes(&$var){
	$var = stripslashes($var);
}
function remove_all_slashes(){
	if (ini_get('magic_quotes_gpc')){
		array_walk_recursive($_POST,'my_strip_slashes');
		array_walk_recursive($_GET,'my_strip_slashes');
		array_walk_recursive($_REQUEST,'my_strip_slashes');
		array_walk_recursive($_COOKIE,'my_strip_slashes');
	}
}
you just call this line on top of your page:

Code: Select all

remove_all_slashes()
You can read more on php.net
http://www.php.net/manual/en/info.confi ... quotes-gpc
Last edited by temidayo on Wed Feb 29, 2012 5:59 pm, edited 1 time in total.
Blaade
Forum Commoner
Posts: 29
Joined: Tue Feb 28, 2012 8:44 am

Re: Problems with email activation

Post by Blaade »

Thanks a lot! If i ever come to Nigeria i'll buy you a drink :drunk:
Think you'll hear more from me in the "Save form data after submitting to a page within website" post i have here :D . That's my next working project but i hope i can manage with some info i got from forums...
Best wishes!
temidayo
Forum Contributor
Posts: 109
Joined: Fri May 23, 2008 6:17 am
Location: Nigeria

Re: Problems with email activation

Post by temidayo »

Blaade wrote:Thanks a lot! If i ever come to Nigeria i'll buy you a drink :drunk:
:D

I just want you to know I edited my last post before this, to include another function
which is needed for remove_all_slashes() to work

Code: Select all

function my_strip_slashes(&$var){
	$var = stripslashes($var);
}
Blaade
Forum Commoner
Posts: 29
Joined: Tue Feb 28, 2012 8:44 am

Re: Problems with email activation

Post by Blaade »

Thank you! Have been of great help.
Post Reply