Click here to Skip to main content
15,885,182 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Here its my html file
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>login form</title>
  </head>
  <body>
    <h3>form</h3>
    <form class="" action="connect.php" method="POST">
      <label for="firstname">enter name</label>
      <input type="text" name="firstname" value="" placeholder="enter first name" required>
      <br><br>
      <label for="lastname">last name</label>
      <input type="text" name="lastname" value="" placeholder="enter last name" required>
      <br><br>
      <label for="email">email</label>
      <input type="email" name="email" value="" placeholder="enter email" required>
      <br><br>
      <label for="password">password</label>
      <input type="password" name="password" value="" placeholder="enter password" required>
      <br><br>
      <label for="cpassword">confirm password</label>
      <input type="password" name="cpassword" value="" placeholder="enter confirm password" required>
      <br><br>
      <input type="submit" name="save" value="submit">
    </form>
  </body>
</html>


Here is my php file

<?php
$servername="localhost";
$username="root";
$password="";
$dbname="demo";
$conn=mysqli_connect($servername,$username,$password,$dbname) or die("connection failed");
if(isset($_POST['save'])){
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$password=$_POST['password'];
$cpassword=$_POST['cpassword'];

$sql="INSERT INTO `users` (`First Name`, `Last Name`, `Email`, `Password`, `Confirm Password`) VALUES ('$firstname', '$lastname', '$email', '$password', '$cpassword')";
$sqlres=mysqli_query($conn,$sql);
if($sqlres){
  echo "data inserted successfully";
}
else {
  echo "data is not inserted";
}
}
 ?>


What I have tried:

I create a simple form and saving its data into database besides it saving data it show my php file on browser
Posted
Updated 10-Sep-21 22:35pm
Comments
Richard Deeming 10-Sep-21 9:52am    
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
PHP: SQL Injection - Manual[^]
PHP: Prepared statements and stored procedures - Manual[^]
Richard Deeming 10-Sep-21 9:53am    
Also, you are storing passwords in plain text. Don't do that:
Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

PHP even has built-in functions to help you do the right thing:
PHP: password_hash[^]
PHP: password_verify[^]
Richard Deeming 10-Sep-21 9:54am    
And you don't need to store the "confirm password" value in the database. You use it to validate that the password and the "confirm password" values are identical. Storing the same value twice serves no purpose.

1 solution

Hi Did you put your html, php file on webserver ?
it show my php file on browser
=> i guest that your did not run from web server
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900