This is the only reason I think I'm having this problem.
user_system
users
1 user_id int(8) No None AUTO_INCREMENT
2 user_name varchar(24) latin1_swedish_ci No None
3 user_password char(40) latin1_swedish_ci No None
4 user_email varchar(128) latin1_swedish_ci No None
Indexes (I think this is the problem)
PRIMARY BTREE Yes No user_id 1 A
user_name BTREE Yes No user_name 1 A
user_activations
1 user_id int(8) No None AUTO_INCREMENT
2 activation_code varchar(10) latin1_swedish_ci No None
Indexes
uni BTREE Yes No user_id 0 A
activation_code 0 A
Here is my codes:
user.inc.php
<?php // Checks if given username exits in database function user_exists($user){ $user = mysql_real_escape_string($user); $total = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `user_name` = '{$user}'"); return (mysql_result($total, 0) == '1') ? true : false; } // Checks if given username and password combo is valid function valid_credentials($user, $pass){ $user = mysql_real_escape_string($user); $pass = mysql_real_escape_string($pass); $total = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `user_name` = '{$user}' AND `user_password` = '{$pass}'"); return (mysql_result($total, 0) == '1') ? true : false; } // Adds user to database 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://website.co.uk/user_system/activate.php?aid={$aid} EMAIL; mail($email, 'Your new account at website.co.uk', $body, 'From: admin@website.co.uk'); 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}')"); } ?>