08.06.2013, 14:49
Ok guys, these weeks I have started developing a browser game since my PHP skills have developed. I am stuck at checking if username already exists.
The registration works perfect however I am able to register multiple accounts with the same name and I can't figure out whats the problem in my code:
Any suggestions?
The registration works perfect however I am able to register multiple accounts with the same name and I can't figure out whats the problem in my code:
Code:
<?php
include("../config/database.config.php");
Function Register()
{
$conn = mysql_connect(HOST,USER,PASS);
mysql_select_db(DATABASE,$conn);
$username = mysql_real_escape_string(trim($_POST['txtusername']));
$password = mysql_real_escape_string($_POST['txtpassword']);
$email = mysql_real_escape_string(trim($_POST['txtemail']));
$username = stripslashes($username);
$password = stripslashes($password);
$email = stripslashes($email);
$checkuser = mysql_query("SELECT * FROM users WHERE username = '". $username ."' OR email = '". $email ."'");
// $password = md5($password);
$salt = sha1(md5($password));
$password = md5($password.$salt);
if (mysql_num_rows($checkuser) > 0 && empty($_POST['txtusername']) == true && empty($_POST['txtpassword']) == true && empty($_POST['txtemail']) === true)
{
header('location:../index.php?p=error');
} else {
$query ="insert into users(username,password,email)values('$username','$password','$email')";
$res = mysql_query($query);
header('location:../index.php?p=success');
}
}
Register();
Any suggestions?