Home > OS >  Data is not entered in Datatbase
Data is not entered in Datatbase

Time:10-20

I am beginner in PHP mysql.

I am trying to make a signup page.

whenever I enter data in text fields it does'nt

go to Database. here is my php code. what changes sould i do to make to make it work.

`<?php
include('db_con.php');

if(isset($_POST['submit'])){
    $email= $_POST['email'];
    $password= $_POST['password'];
    $confirm_pass= $_POST['confirm_pass'];

    $query = mysqli_query($conn, "insert into mydb(email, password, confirm_pass)value('$email', '$password','$confirm_pass')");

    if($query)
    {
        echo "<script>alert('account created successfully');</script>";
    }
    else{
        echo "<script>alert('something went missing');</script>";
    }
}

?>
<!DOCTYPE html>

<!-- JavaScript Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
 integrity="sha384-OERcA2EqjJCMA /3y gxIOqMEjwtxJY7qPCqsdltbNJuaOe923 mo//f6V8Qbsw3" crossorigin="anonymous"></script>

<html method="POST">
<form>
  <label for="email">Email:</label><br>
  <input type="text"  required id="email" name="email"><br>
  
  <label for="password">Password</label><br>
  <input type="text"  required id="password" name="password"><br>

   <label for="confirm_pass">confirm password</label><br>
  <input type="text"  id="confirm_pass" name="confirm_pass"><br>
  <button type="submit" name="submit" >Submit</button>
</form>

?>`

CodePudding user response:

Right way of inserting is

INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...)

You can try this code

<?php
include('db_con.php');

if(isset($_POST['submit'])){
    $email= $_POST['email'];
    $password= $_POST['password'];
    $confirm_pass= $_POST['confirm_pass'];

    $query = mysqli_query($conn, "insert into mydb(email, password, confirm_pass) values ('$email', '$password', '$confirm_pass')");

    if($query)
    {
        echo "<script>alert('account created successfully');</script>";
    }
    else{
        echo "<script>alert('something went missing');</script>";
    }
}

?>

<!DOCTYPE html>

<!-- JavaScript Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
 integrity="sha384-OERcA2EqjJCMA /3y gxIOqMEjwtxJY7qPCqsdltbNJuaOe923 mo//f6V8Qbsw3" crossorigin="anonymous"></script>

<html>
<form method="POST">
  <label for="email">Email:</label><br>
  <input type="text"  required id="email" name="email"><br>
  
  <label for="password">Password</label><br>
  <input type="text"  required id="password" name="password"><br>

   <label for="confirm_pass">confirm password</label><br>
  <input type="text"  id="confirm_pass" name="confirm_pass"><br>
  <button type="submit" name="submit" >Submit</button>
</form>

CodePudding user response:

try this

mysqli_query($conn, "INSERT INTO mydb (email, password, confirm_pass) VALUES ('$email', '$password','$confirm_pass')");

you left 1 letter S in VALUES

  • Related