Autor Zpráva
Matej Ševčík
Profil
Caute, pise mi dve chybove hlasky. Neviem preco a vobec mi to nefunguje. Skusal som uz vselico ale neviem :). Nevedel som kde tak vam sem dam cely kod aj ked je trochu dlhsi. Chyba je konkretne v Logine.

chybove hlasky:


Notice: Undefined index: hidden_register in C:\xampp\htdocs\post\index.php on line 8

Fatal error: Call to a member function fetchColumn() on a non-object in C:\xampp\htdocs\post\index.php on line 56

<?php 
    session_start();
    $pdo = new PDO('mysql:host=localhost;dbname=post_db', 'root', '');

    /*
    * REGISTRATION
    */
    if ($_POST['hidden_register'] == "hidden")
    {
        if ($_POST['year'] != date('Y'))
        {
            $error_register = "<h3 class='error'>Antispam is not correct.</h3>";
        }

        elseif ($_POST['password'] != $_POST['password_again'])
        {
            $error_register = "<h3 class='error'>Enter your password.</h3>";
        }

        elseif (strlen($_POST['nickname']) < 4)
        {
            $error_register = "<h3 class='error'>Nickname must be longer.</h3>";
        }

        elseif ($_POST['password'] == $_POST['nickname'])
        {
            $error_register = "<h3 class='error'>Enter a different password.</h3>";
        }

        elseif (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
        {
            $error_register = "<h3 class='error'>Enter real email.</h3>";
        }

        else 
        {
            $query_reg = $pdo->prepare('INSERT INTO users (nickname, email, password) VALUES (?, ?, ?)');
            $query_reg_a = array($_POST['nickname'], $_POST['email'], "ad*(02/a" . $_POST['password'] . "t4@kl*^");
            $query_reg->execute($query_reg_a);

            header('Location: admin.php');
            $_SESSION['nickname'] == $_POST['nickname'];
        }
    }

    /*
    * LOGIN
    */
    if ($_POST['hidden_login'] == "hidden")
    {
        if ($_POST['nickname'] && $_POST['password'] != "")
        {
            
            $query_log = $pdo->prepare("SELECT users_id FROM users WHERE nickname = ? AND password = ?");
            $query = $query_log->execute(array($_POST['nickname'], "ad*(02/a" . $_POST['password'] . "t4@kl*^"));
            $data = $query->fetchColumn();

            if (!$data)
            {
                $error_login = "<h3 class='error'>User doesn't exist.</h3>";
            }

            else
            {
                header('Location: admin.php');
                $_SESSION['nickname'] == $_POST['nickname'];
            }
        }

        else
        {
            $error_login = "<h3 class='error'>Enter nickname and password.</h3>";
        }
    }
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">

    <!--Styles-->
    <link rel="stylesheet" href="css/style.css">

    <!--Fonts-->
    <link href='http://fonts.googleapis.com/css?family=Open+Sans&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Indie+Flower' rel='stylesheet' type='text/css'>

    <!--Title-->
    <title>POST it</title>
</head>
<body>
    <div class="wrap">
        <header>
            <h1><a href="index.php">POST <span>it</span></a></h1> <!--Heading "POST it"-->
        </header>
        <main>
            <h2>Welcome to POST it. Login or Register</h2>

            <!--Login-->
            <div id="login">
                <h2>Login</h2>
                <?php 
                    if(isset($error_login))
                        echo "$error_login";
                ?>
                <form action="" method="post">
                    <label>Nickname:</label> <br>
                    <input type="text" name="nickname"> <br>
                    <label>Password:</label> <br>
                    <input type="password" name="password"> <br>
                    <input type="hidden" name="hidden_login" value="hidden">
                    <input type="submit" value="Login">
                </form>
            </div>

            <!--Register-->
            <div id="register">
                <h2>Registration</h2>
                <?php 
                    if(isset($error_register))
                        echo "$error_register";
                    ?>
                    <form action="" method="post">
                    <label>Nickname:</label> <br>
                    <input type="text" name="nickname"> <br>
                    <label>Email:</label> <br>
                    <input type="email" name="email"> <br>
                    <label>Password:</label> <br>
                    <input type="password" name="password"> <br>
                    <label>Password again:</label> <br>
                    <input type="password" name="password_again"> <br>
                    <label>Actual year:</label> <br>
                    <input type="text" name="year"> <br>
                    <input type="hidden" name="hidden_register" value="hidden">
                    <input type="submit" value="Register">
                </form>
            </div>
        </main>
    </div>
</body>
</html>
lionel messi
Profil
Matej Ševčík:
1. Nikde nekontroluješ, či $_POST['hidden_register'] skutočne existuje. S premennou pracuj iba ak bola nastavená, čo overíš pomocou if (isset($_POST['hidden_register']).

2. Vyzerá to na zlyhanie SQL dotazu. Skús hneď po pripojení k PDO pridať riadok:
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);

A daj vedieť, či sa vyhodí varovanie.

3. Ideálne by bolo spustiť si dotaz priamo trebárs v PHPMyAdminovi.
Matej Ševčík
Profil
Ďakujem :) .. Už som to opravil. Neviem ako iba som nakopíroval ten istý kód z druhého súboru. Inak na kód čo hovoríš? :)

Edit: ten kód čo si mi poslal som tam dal.

nejako takto:

    if (isset($_POST['hidden_register'])
    {
        if ($_POST['year'] != date('Y'))
        {
            $error_register = "<h3 class='error'>Antispam is not correct.</h3>";
        }

hádže to chybu
martin1312
Profil
máš tam chybu, chýba ti na konci zátvorka:
if (isset($_POST['hidden_register']))
Matej Ševčík
Profil
martin1312:
nevšimol som si :) ďakujem

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm: