I have index.html to post data in send.php the send.php code is the form data is named correctly & no error on send page
<?php
$servername = "localhost";
$username = "Blah Blah";
$password = "Blah Blah";
$dbname = "Blah Blah";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$name = $_POST['name'];
$famil = $_POST['famil'];
$email = $_POST['email'];
$amount = $_POST['amount'];
$sql = "INSERT INTO users".
"(name, famil, email, amount)".
"VALUES ('$name','$famil','$email','$amount')";
mysqli_close($conn);
but query can't insert the data into db!
why the post method won't work here?
The problem is that you're not querying -
mysqli_query()
is missing which is the essential part.Your current code is indeed valid, yet SQL failed silently because of the missing
mysqli_query()
.Make sure that your form elements are named also and that your form is a POST method. (An insight)
I.e.:
name="name"
,name="famil"
etc. and<form method="post" action="handler.php">
Use
mysqli
with prepared statements, or PDO with prepared statements,they're much safer to use.
Add error reporting to the top of your file(s) which will help find errors.
Sidenote: Error reporting should only be done in staging, and never production.
You can also use
or die(mysqli_error($conn))
tomysqli_query()
For added protection with your existing code, use:
Doing this would also work:
or