Error declaring variable in login system

1

I'm doing a login system and now I come across a "Notice" that indicates that my Variable is not set. This variable is not entered by the form. It is defined by a function that will generate a key. KeyGenerator() ;

I checked several times and got the table correctly in the database. I've looked at all the ways to declare an empty variable and I can not seem to get the error. Does anyone know how to do it?

The error is given in the line when I enter the data in the database:

  

"Notice: Undefined variable: userkey in C: \ Program   Files \ EasyPHP-DevServer-14.1VC9 \ data \ localweb \ panel \ system \ database.php   on line 7 You have an error in your SQL syntax; check the manual that   correspond to your MySQL server version for the right syntax to use   near '@ servidor.com, Ana78, 40bd001563085fc35165329ea1ff5c5ecbdbbeef,   , 1456576578, 1) 'at line 1'

<?php 
// CADASTAR O USUARIO
    function Register($name, $mail, $username, $password,  $status = true){
        $password = CryptPassword($password);
        $userKey  = KeyGenerator();
        $register = time();
        $query    = "INSERT INTO membros (name, mail, username, password, userkey, register, status) VALUES ($name, $mail, $username, $password, $userkey, $register, $status)";

        return mysql_query($query) or die(mysql_error());
    }

// VERIFICA SE LOGIN EXISTE
    function UserNameExists($username){
        $query  = "SELECT username FROM membros WHERE username = '$username'";
        $result = mysql_query($query) or die(mysql_error());
        if(mysql_num_rows($result) <= 0)
            return true;
        else
            return false;
    }


// VERIFICA SE EXISTE E-MAIL
    function MailExists ($mail){
        $query  = "SELECT mail FROM membros WHERE mail = '$mail'";
        $result = mysql_query($query) or die(mysql_error());
        if(mysql_num_rows($result) <= 0)
            return true;
        else
            return false;
    }

// CONEXAO COM BANCO DE DADOS
    function connect(){
        $conn = mysql_connect(HOSTNAME, USERNAME, PASSWORD);

        if (!$conn)
            die(mysql_error());
            else {
                mysql_select_db(DATABASE, $conn ) or die(mysql_error());

                mysql_query("SET NAME 'utf-8");
                mysql_query("SET character_set_connection=utf8");
                mysql_query("SET character_set_client=utf8");
                mysql_query("SET character_set_results=utf8");


            }

    }

 ?>

Function:

    function KeyGenerator(){
        return rand();
    }

Form:

<?php 
    require_once $_SERVER['DOCUMENT_ROOT'].'/painel/system/system.php';
    AccessPublic();
 ?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Registar</title>
</head>
<body>

<h2>Registar</h2>
<hr>


<?php ValidateFormRegister(); ?>

<form action="" method="post">

    <label for="">Nome</label><br/>
        <input type="text" name="name" value="<?php echo GetPost('name'); ?>"><br/><br/>

    <label for="">E-Mail</label><br/>
        <input type="text" name="mail" value="<?php echo GetPost('mail'); ?>"><br/><br/>

    <label for="">Usuário</label><br/>
        <input type="text" name="username" value="<?php echo GetPost('username'); ?>"><br/><br/>

    <label for="">Palavra-Passe</label><br/>
        <input type="password" name="password"><br/><br/>

    <label for="">Confirme a Palavra-Passe</label><br/>
        <input type="password" name="confirm"><br/><br/>

    <input type="submit" name="send" value="Registar">

    <a href="<?php echo URL_BASE; ?>">LOGAR-SE</a>




</form>

</body>
</html>
    
asked by anonymous 27.02.2016 / 13:51

1 answer

2

There is a difference in case of the variable name in PHP.

$userKey = "exemplo"; // no seu caso: $userKey = KeyGenerator();
echo $userkey; // vai dar erro (K minúsculo), $userkey != $userKey
echo $userKey; // está correto

link :

  

Variables in PHP are represented by a dollar sign ($) followed by the variable name. Variable names in PHP are case-sensitive.

Use $userKey and should work:

$query = "INSERT INTO membros (name, mail, username, password, userkey, register, status) VALUES ($name, $mail, $username, $password, $userKey, $register, $status)";
    
27.02.2016 / 14:23