I developed the create function for my PHP CRUD, the database connection is successful, but when I post the data, it doesn’t do anything. It should either say that the data is posted successfully or that there is an error.
I have two pages:
connect.php:
<?php
$con = new mysqli('localhost', 'root', '', 'crudoperation');
if(!$con){
die(mysqli_error($con));
}else{
echo 'database connection successfully established';
}
?>
and user.php
<?php
include 'connect.php';
if (isset($_POST['submit'])){ // si on appuye sur submit, poster tous les champs
$name=$_POST['name'];
$email=$_POST['email'];
$mobile=$_POST['mobile'];
$password=$_POST['password'];
$sql="insert into `crud` (name, email, mobile, password)
values('$name','$email','$mobile','$password')";
$result=mysqli_query($con, $sql);
if($result){
echo "Data inserted successfully";
}else{
die(mysqli_error($con));
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CRUD PHP</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>
<body>
<div class="container my-5">
<form method="post">
<div class="mb-3">
<label>Name</label>
<input type="text" class="form-control" placeholder="Enter your name" name="name" autocomplete="off">
</div>
<div class="mb-3">
<label>Email</label>
<input type="email" class="form-control" placeholder="Enter your email" name="email" autocomplete="off">
</div>
<div class="mb-3">
<label>Mobile</label>
<input type="text" class="form-control" placeholder="Enter your mobile number" name="mobile" autocomplete="off">
</div>
<div class="mb-3">
<label>Password</label>
<input type="password" class="form-control" placeholder="Enter your password" name="password" autocomplete="off">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-0pUGZvbkm6XF6gxjEnlmuGrJXVbNuzT9qBBavbLwCsOGabYfZo0T0to5eqruptLy" crossorigin="anonymous"></script>
</body>
</html>
What can be the problem ?
I removed the name="submit" I previously had and instead of showing me a white screen, it showed me the same forms as before submitting.