0

I have made 3 pages: form, database connection and registration page. I am not getting any error but when I register a new user on the form page, it does not apear on phpmyadmin dashboard.

Please help me

What should I do?

My form is here:

<!DOCTYPE html> <html> <head>
    <title></title>     <meta charset="utf-8"> </head> <body>   <div
 style="background-color: #222; color: #fff; height: 50px; width:
 100%;"></div>  <style type="text/css">     body{       background-color:
 #e1e1e1;   }       form{           margin-top: 20px;           background-color: #fff;

        }       form input{             padding: 4px;       }

        button{             width: 100px;           height: 35px;           background-color: #222;
            color: #fff;            margin-top: 10px;           border: 2px dotted;         }
            </style> <form action="register.php" method="POST">         Forname:<br>    <input type="text" name="first" id="first"
 size="50"><br>     Aftername:<br>  <input type="text" name="last"
 size="50"><br>     E-post:<br>     <input type="text" name="email"
 size="50"><br>     Username:<br>   <input type="text" name="username"
 size="50"><br>     Password:<br>   <input type="password" name="password"
size="50"><br>  <button type="submit" name="submit"
 id="btn-submit">Sign Up</button>

 </form> </body> </html> 

My database connection:

 <?php  $conn =
     mysqli_connect("127.0.0.1","root", "","test1"); if (!$conn) {
        die("You can't connect to the database");

     } else echo "Your registration is succesed";

      ?>

My registration page:

 <?php require 'db.php'; ?> <?php

     if(isset($_POST['submit'])){   session_start(); $hostname =
     "127.0.0.1"; $username = "root"; $password = ""; $database = "login";

     $first = $_POST['first']; $last = $_POST['last']; $email =
     $_POST['email']; $username = $_POST['username']; $password =
     $_POST['password'];


     $sql = $conn->query("INSERT INTO
     users(first,last,email,username,password)values('{$first}','{$last}','{$email}','{$password}')");
     header('Location: login.php'); }

     ?>
Chirag Jain
  • 1,367
  • 1
  • 11
  • 27
web lover
  • 1
  • 1
  • 1
    **Danger**: You are **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that you need to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Oct 20 '17 at 17:52
  • 1
    **Danger**: "Not hashing at all" is [an unsuitable hashing algorithm](http://php.net/manual/en/faq.passwords.php); you need to [take better care](https://www.owasp.org/index.php/Password_Storage_Cheat_Sheet) of your users' passwords. – Quentin Oct 20 '17 at 17:52

1 Answers1

0

For insert into SQL, you are suggested to display the error whether it's inserted or not, example from w3school: PHP insert Data into MySQL

And based on your code, you miss the $username column value, replace to this and problem solved

$sql = "INSERT INTO users(first,last,email,username,password)
        values('{$first}', '{$last}', '{$email}', '{$username}', '{$password}')";
if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}
Momo
  • 482
  • 5
  • 19