mardi 4 août 2015

PHP - MySQL I always got username exists, but why? [duplicate]

This question already has an answer here:

I tried echo($numrows);

numrows is equal to 0. then why i got this error : username exists?

I went trough it all many times, but I can't find what is the problem..

<?php

function generateRandomString($length = 6) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}

//innen regiszt:
$username = strip_tags($_POST['username']);
$email1 = strip_tags($_POST['email1']);
$email2 = strip_tags($_POST['email2']);
$pw1 = strip_tags($_POST['pw1']);
$pw2 = strip_tags($_POST['pw2']);

if($username&&$email1&&$email2&&$pw1&&$pw2)
    {
     if ($email1==$email2)
         {
             if ($pw1==$pw2)
             {               
                 if (5<strlen($pw1)&&20>=strlen($pw1))
                 {
                    if (5<strlen($pw1)&&20>=strlen($pw1)) 
                    {                       
                    $connect = mysql_connect('HOST','UNAME','PW');
                    $database = mysql_select_db('virtualtc',$connect);  
                    $query = mysql_query("SELECT * FROM users WHERE username='$username'");
                    $querymail = mysql_query("SELECT * FROM users WHERE email='$email1'");
                    $numrowsmail = mysql_num_rows($querymail);
                    $numrows = mysql_num_rows($query);
                       if ($numrows=0)
                       {
                            if ($querymail=0)  
                            {
                                $md5pass= md5($pw1);
                                $date=date("Y-m-d");
                                $query3 = mysql_query(
                                    "INSERT INTO users VALUES '','$username','$md5pass','$email1', 0 ,'$date'");
                                include("registration_complete.php");//regist

                            }else include("/errors/email_exists.html");//email exists
                       }else include("/errors/user_exists.html")//user exists                   
                    }else include("/errors/uname_length.html");//username length 6-20!                   
                 }else include("/errors/pass_length.html"); //password length 6-20!              
             } else include("/errors/different_pw.html");//different password
         } else include("/errors/different_email.html");//different email
    } else include("/errors/empty_regist.html");//empty field


?>

Aucun commentaire:

Enregistrer un commentaire