0

I Need some help with my script. When I go to the MySQL Database and insert a new User I can log in with my username and Password, which I can create through the MySQL database.

But my register-page.php script doesn't work somehow. It doesn't fill the database with new data from user Registration. Can you solve the Problem please? Thanks.

The Problem which appears is ERROR while Register. It is my own error message.

<?php
session_start();
if(isset($_SESSION['sig']))
{
    echo('<script> window.location="index.php" </script>');
}
if(isset($_REQUEST['submit']))
{
    $username = $_REQUEST['UserName'];
    $password = $_REQUEST['UserPassword'];
    include('db_login.php');
    $query = mysqli_query($connection, "SELECT * FROM UserTable WHERE UserName='".$username."' AND UserPassword='".$password."'");
    $row = mysqli_fetch_array($query);
    if(empty($row))
    {
        echo('<script> alert("This User could not be found, please try again!"); </script>');
    }
    else
    {
        $_SESSION['sig'] = "OK";
        $_SESSION['UserName'] = $username;
        echo('<script> window.location="dashboard.php" </script>');
    }
}
if(isset($_REQUEST['submitregister']))
{
    $username_reg = $_REQUEST['UserName'];
    $password_reg = $_REQUEST['UserPassword'];
    include('db_login.php');
    $query = mysqli_query($connection, "INSERT INTO UserTable (UserName, UserPassword) VALUES ('".$username_reg."','".$password_reg."');") or die ("ERROR while register");
    echo('<script> window.location="dashboard.php" </script>');
}
?>

REGISTER-PAGE.php

<?php
session_start();
if(isset($_REQUEST['submitregister']))
{
    $userinfo_reg = $_REQUEST['UserInfo'];
    $username_reg = $_REQUEST['UserName'];
    $password_reg = $_REQUEST['UserPassword'];
    include('db_login.php');
    // Melde alle PHP Fehler (siehe Changelog)
    $query = mysqli_query($connection, "INSERT INTO UserTable (UserInfo, UserName, UserPassword) VALUES ('".$userinfo_reg."','".$username_reg."','".$password_reg."');") or die ("ERROR while register");
    echo('<script> window.location="dashboard.php" </script>');
}
?>

INDEX.php

IMAGES:

https://www.file-upload.net/download-13475231/indexpage.PNG.html
https://www.file-upload.net/download-13475230/register-page.PNG.html

Please help me, thanks.

user3783243
  • 4,418
  • 5
  • 14
  • 34
  • there is a typo in your register query – Saurabh Sharma Jan 19 '19 at 12:50
  • You have two insert queries? Replace `ERROR while register` with error reporting. Don't put user data directly into SQL, parameterize the query. Don't store passwords as plain text, hash them. – user3783243 Jan 19 '19 at 12:55
  • You probably also are better off storing those images on imgur, or some site that allows displaying (or even here). I'm not downloading files. Is `INDEX.php` the first script block? Is the `insert` being run in the first block or `REGISTER-PAGE.php`? – user3783243 Jan 19 '19 at 13:15
  • @SaurabhSharma where exactly ? What do you mean ? What do I have to replace with what ? – Trading Sergey Jan 19 '19 at 13:36
  • @user3783243 can you explain better please what to do, I am a noob :D – Trading Sergey Jan 19 '19 at 13:44
  • 1
    See http://php.net/manual/en/mysqli.quickstart.prepared-statements.php for how to parameterize. See http://php.net/manual/en/mysqli.error.php for proper error reporting. Use http://php.net/manual/en/function.password-hash.php for storing the password. Use http://php.net/manual/en/function.password-verify.php to verify. As currently written you have two insert statements, it is hard to tell which you have issues with. One doesn't have the `UserInfo` insert. If that field is required you will get an error. – user3783243 Jan 19 '19 at 13:48
  • @user3783243 I deleted now the one of the two inserts. I seperated it in index.php and register-page.php. But it still doesnt work to Register, still error message... – Trading Sergey Jan 19 '19 at 14:02
  • Follow the links and it should tell you what is wrong, make your code secure, and make your code function. – user3783243 Jan 19 '19 at 14:24

0 Answers0