-3

I am a beginner in PHP. And decided to make a fully working model of a registration form. But when I program it, it doesn't work.

Here is the main HTML code

<html>
    <form method="POST">
       <input required type="text" name="name" placeholder="Your Name"><br>           
       <input required type="email" name="email" placeholder="Your Email"><br>
       <input required type="password" name="pass" placeholder="Your Password"><br>
       <button name="submit" type="submit" value="Submit">Submit</button>
    </form>
</html>

Here is the PHP code

<?php
$conn = mysqli_connect("localhost", "root", "", "shayeq");

if (isset($_POST['submit'])) {
       # code...
       $user = $_POST['name'];
       $email = $_POST['email'];
       $pass = $_POST['pass'];

       $sql = "INSERT INTO 'user'(name, email, password) VALUE ('$user', '$email', '$pass')"
   }    
Shayeq
  • 1
  • 1
  • Welcome to SO ... what "doesn't work"? what are you expecting to happen and what is actually happening? – lagbox Jan 04 '21 at 03:37
  • 1
    You need to actually run the SQL Command.....You currently only have a string variable created. Also, please look into PDO and/or Prepared Statements as you're vulnerable to SQL Injections. Best to start your programming experience the correct way! ;) – Darren Jan 04 '21 at 03:59
  • 1
    **Never store passwords in clear text or using MD5/SHA1!** Only store password hashes created using PHP's [`password_hash()`](https://php.net/manual/en/function.password-hash.php), which you can then verify using [`password_verify()`](https://php.net/manual/en/function.password-verify.php). Take a look at this post: [How to use password_hash](https://stackoverflow.com/q/30279321/1839439) and learn more about [bcrypt & password hashing in PHP](https://stackoverflow.com/a/6337021/1839439) – Dharman Jan 04 '21 at 11:09

1 Answers1

-1

You have to run sql command.

$sql = "INSERT INTO user (name, email, password) VALUES ('$user', '$email', '$pass')";

$result = mysqli_query($sql);
Emcee
  • 47
  • 4