Page 1 of 1

Email Activations.

Posted: Sun Aug 14, 2011 8:00 pm
by wizzuriz
Hello Again.

I like to say that I really like the help I get here.

Now the thing is I don´t understand why I get this error ( its the Email activation part on the user_system )

this is my error : Warning: mysql_result() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/user_system/core/inc/user.inc.php on line 37

This is my code.
// check if the user account is active. 
function is_active($user){
    $user = mysql_real_escape_string($user);
    
    $sql = "SELECT
                COUNT(`user_activations`, `user_id`)
                FROM `users`
                INNER JOIN `user_activations`
                ON `users`, `user_id` = `user_activations`, `user_id`
                WHERE `users` `user_name` = '{$user}'";
    
    $result = mysql_query($sql);
    
    return (mysql_result($result, 0) == '0') ? true : false;
    
}
Please let me know what I do wrong here.

A other thing, If I have some code I like for you to look in to do you then take orders? I mean if I pay for it can you help me with some hard ( well hard to me ) code. :)

Best regards
Wizzuriz

Re: Email Activations.

Posted: Sun Aug 14, 2011 8:22 pm
by jacek
 ON `users`, `user_id` = `user_activations`, `user_id`
You have the wrong syntax here, it should be
`table_name`.`column_name`

Re: Email Activations.

Posted: Sun Aug 14, 2011 8:40 pm
by wizzuriz
Hello Again.

Thanks for the fast replay, now I did check that and still I get the error.

This is my now code. , = . now.
// check if the user account is active. 
function is_active($user){
    $user = mysql_real_escape_string($user);
    
    $sql = "SELECT
                COUNT(`user_activations`, `user_id`)
                FROM `users`
                INNER JOIN `user_activations`
                ON `users`.`user_id` = `user_activations`, `user_id`
                WHERE `users`.`user_name` = '{$user}'";
    
    $result = mysql_query($sql);
    
    return (mysql_result($result, 0) == '0') ? true : false;
    
}

Re: Email Activations.

Posted: Sun Aug 14, 2011 8:46 pm
by wizzuriz
A other thing is that I don´t get my Email, do you know what could be wrong?

this is my code.
/ adds a user to the databse.
function add_user($user, $email, $pass){
    $user   = mysql_real_escape_string(htmlentities($user));
    $email  = mysql_real_escape_string($email);
    $pass   = sha1($pass);
    
    $charset = array_flip(array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9)));
    $aid = implode('', array_rand($charset, 10));
    
    $body = <<<EMAIL
    
    Hi,
    
    Thanks for registering, before you login you need to activate your account.
    
    To do that simply click the following link.
    
    http://192.168.1.10/user_system/activat ... ?aid={$aid}
   


EMAIL;
    
    mail($email, 'Your new account at test.com', $body, 'FROM:admin@testole1.com');
    
    
    mysql_query("INSERT INTO `users` (`user_name`, `user_password`, `user_email`) values ('{$user}', '{$pass}', '{$email}')");
    
    $user_id = mysql_insert_id();
    
    mysql_query("INSERT INTO `user_activations` (`user_id`, `activation_code`) VALUES ({$user_id}, '{$aid}')");
}
Please let me know.

best regards
Wizzuriz

Re: Email Activations.

Posted: Mon Aug 15, 2011 11:46 am
by jacek
wizzuriz wrote:Thanks for the fast replay, now I did check that and still I get the error.
You forgot the other column
`user_activations`, `user_id`
wizzuriz wrote:A other thing is that I don´t get my Email, do you know what could be wrong?
mail($email, 'Your new account at test.com', $body, 'FROM:admin@testole1.com');
You have the header wrong here, it should be
mail($email, 'Your new account at test.com', $body, 'From: admin@testole1.com');
But the most likely thing is that you are running into spam filtering.

Re: Email Activations.

Posted: Mon Aug 15, 2011 2:49 pm
by wizzuriz
Hello Again.

I got all working but the Email, I still don't get the E-mail and I did check the spam filter.
// adds a user to the databse.
function add_user($user, $email, $pass){
    $user   = mysql_real_escape_string(htmlentities($user));
    $email  = mysql_real_escape_string($email);
    $pass   = sha1($pass);
    
    $charset = array_flip(array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9)));
    $aid = implode('', array_rand($charset, 10));
    
    $body = <<<EMAIL
    
    Hi,
    
    Thanks for registering, before you login you need to activate your account.
    
    To do that simply click the following link.
    
    http://192.168.1.10/user_system/activat ... ?aid={$aid}
   


EMAIL;
    
    mail($email, 'Your new account at test.com', $body, 'FROM: admin@test.com');
    
    
    mysql_query("INSERT INTO `users` (`user_name`, `user_password`, `user_email`) values ('{$user}', '{$pass}', '{$email}')");
    
    $user_id = mysql_insert_id();
    
    mysql_query("INSERT INTO `user_activations` (`user_id`, `activation_code`) VALUES ({$user_id}, '{$aid}')");
}
?>
I Don't know if there is any way I can check that its not my setting or something other then the code.

Please let me know if you see anything in the code or if you have any idea about what cloud be wrong.

Thanks for the help.

Best Regards
Wizzuriz.

Re: Email Activations.

Posted: Mon Aug 15, 2011 11:20 pm
by jacek
Are you running this script locally ? Some ISPs don't allow email to be sent out using their network to prevent spam so that could be it, it could also be your router or somethign blocking the connection.

If you add var_dump() around the mail function like this
var_dump(mail($email, 'Your new account at test.com', $body, 'From: admin@testole1.com'));
do you get bool(true) or bool(false) ?

The best thing to do here would be to either try this on a webhost or just assume that it will work when you upload it.

EDIT: You could also try sending it to a different address, ideally not gmail or hotmail.