Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Checking if user exists
#1
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:

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?
Reply


Messages In This Thread
Checking if user exists - by parat26 - 08.06.2013, 14:49
RE: Checking if user exists - by SlimShady95 - 08.06.2013, 15:52
RE: Checking if user exists - by parat26 - 08.06.2013, 20:00
RE: Checking if user exists - by portuges23 - 09.06.2013, 00:49
RE: Checking if user exists - by SlimShady95 - 09.06.2013, 20:03
RE: Checking if user exists - by portuges23 - 11.06.2013, 13:50
RE: Checking if user exists - by SlimShady95 - 11.06.2013, 14:18
RE: Checking if user exists - by Milu2K - 19.06.2013, 13:05
RE: Checking if user exists - by SlimShady95 - 19.06.2013, 16:54
RE: Checking if user exists - by Milu2K - 19.06.2013, 17:52
RE: Checking if user exists - by Yannici - 19.06.2013, 21:39
RE: Checking if user exists - by SlimShady95 - 19.06.2013, 22:31
RE: Checking if user exists - by Steffen - 22.06.2013, 18:29
RE: Checking if user exists - by Yannici - 24.06.2013, 13:34
RE: Checking if user exists - by Milu2K - 26.06.2013, 14:23
RE: Checking if user exists - by Steffen - 26.06.2013, 14:41
RE: Checking if user exists - by Milu2K - 26.06.2013, 14:47
RE: Checking if user exists - by portuges23 - 24.03.2014, 18:52



Users browsing this thread: 1 Guest(s)