0

I am trying to insert data in the database but it is neither working nor showing the error

below is the form

 <form id="RegForm" action= "reglogic.php" method= "POST">
                   <input type="text" name= "firstname" placeholder="firstname" required>
                   <input type="text" name= "lastname" placeholder="lastname" required>
                   <input type="text" name= "username" placeholder="username" required>
                   <input type="email" name= "email" placeholder="email" required>
                   <input type="password" name= "password" placeholder="password" required>
                   <button type="submit" name="submit" class="btn">Register</button>
               </form>

the php logic

<?php

include "../database/connexion.php";

if(isset($_POST['submit']){
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $username = $_POST['username'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    $hashpassword = md5($password);
    $role = 2;
    
    $sql = "INSERT INTO users (first_namse, last_name, username, email, password, role_ID) VALUES ('$firstname', '$lastname', '$username', '$email', '$hashpassword', '$role')";
  if(mysqli_query($conn, $sql)) {
  echo "New record created successfully";
   } else {
     echo "Error: " . $sql . "<br>" . mysqli_error($conn);
    }
   mysqli_close($conn);
}

?>

connection

 <?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "techmarket";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check connection
if ($conn === false) {
  die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?> 

And the only output I get is this one

" . mysqli_error($conn); } mysqli_close($conn); } ?> 

Please highlight me on this

I try all the possibility even putting the connection in the same page

  • 2
    Do you have PHP installed? This looks like your PHP has been interpreted as plain HTML. Try the most basic PHP script: ` – KIKO Software Feb 12 '23 at 17:02
  • 1
    Another way to see PHP is not running, check 'view source'. Do you see PHP code? If yes, PHP is not installed/running. – Evert Feb 12 '23 at 17:31
  • **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 Feb 12 '23 at 17:35
  • **Danger**: You are using [an unsuitable hashing algorithm](http://php.net/manual/en/faq.passwords.php) and need to [take better care](https://www.owasp.org/index.php/Password_Storage_Cheat_Sheet) of your users' passwords. – Quentin Feb 12 '23 at 17:35

0 Answers0