GrowingDev GrowingDev - 2 months ago 5x
MySQL Question

Cannot insert form data into a MySQL database using PHP

I am trying to insert data submitted in a form, into a MySQL Database, and I can't see the problem in my code(except for MySQL injection, that I will work to resolve after actually being able to insert any data). I have searched in StackOverflow, and found someone who probably worked by the same manual, but I work in localhost, he's on GoDaddy. The solution given there don't work for me.
Link to the spoken answer

Here is my code for the HTML and the PHP code:

$Fname = $_POST['FirstName'];
$Lname = $_POST['LastName'];
$Email = $_POST['Email'];
$pw = $_POST['Password'];

$sql= $con->query("INSERT INTO user (Fname,Lname,Email,Password) values('{$Fname}', '{$Lname}', '{$Email}', '{$pw}')");

<!DOCTYPE html >
<link href="css/Master.css" rel="stylesheet" type="text/css" />
<link href="css/Menu.css" rel="stylesheet" type="text/css" />


<div class="container">
<div class="header">

<div class="menu">
<div id="NavBar">
<a href="Login.php">Login</a>
<a href="Register.php">Register</a>

<div class="leftBody"></div>
<div class="rightBody">
<form action="" method="post" name="RegisterForm" id="RegisterForm">
<div class="FormElement">
<input name="FirstName" id="FirstName" type="text" placeholder="First Name" class="TField">
<div class="FormElement">
<input name="LastName" id="LastName" type="text" placeholder="Last Name" class="TField">
<div class="FormElement">
<input name="Email" id="Email" type="email" placeholder="E-Mail" class="TField">
<div class="FormElement">
<input name="Password" id="Password" type="password" placeholder="Password" class="TField">
<input name="Register" id="Register" type="button" value="Register" class="regButton">

<div class="footer"></div>



And this is my connection.php file:
That it does show that it connects.

if (!$con) {
die("Could not connect: " . mysqli_error());
echo "Connected successfully";

And a picture of my database in phpMyAdmin:

I have tried also using this line like this for some reason, but to no avail.:

$sql= $con->query("INSERT INTO user
values ('Fname', 'Lname', 'Email', 'pw')");

Any help would be greatly appreciated. Thanks!


i didn't see submit button that actually submit the form. So if i am not wrong please try to use

<input name="Register" id="Register" type="submit" value="Register" class="regButton">