Here is my HTML form:
<form action="PHP/Signup.php" method="POST">
<input type="text" name="FirstName" placeholder="Firstname" required="true"><br><br>
<input type="text" name="MiddelName" placeholder="Middelname"><br><br>
<input type="text" name="LastName" placeholder="Lastname" required="true"><br><br>
<input type="text" name="Username" placeholder="Username" required="true"><br><br>
<input type="password" name="Password" placeholder="Password" required="true"><br><br>
<input type="email" name="Email" placeholder="Email address" required="true"><br><br>
<input type="text" name="Phone" placeholder="Phone number"><br><br>
<input type="text" name="Class" placeholder="Enter your class code eks. 2MKA" required="true"><br><br>
<button type="submit">SIGN UP</button>
</form>
and here is my PHP code (PHP/Signup.php):
<?php
session_start();
include 'PHP/ConfigMamp.php';
$FirstName = $_POST['FirstName'];
$MiddelName = $_POST['MiddelName'];
$LastName = $_POST['LastName'];
$Username = $_POST['Username'];
$Password = $_POST['Password'];
$Email = $_POST['Email'];
$Phone = $_POST['Phone'];
$Class = $_POST['Class'];
//Test to see if the form acctully gets posted
//echo $FirstName. "<br>";
//echo $MiddelName. "<br>";
//echo $LastName. "<br>";
//echo $Username. "<br>";
//echo $Password. "<br>";
//echo $Email. "<br>";
//echo $Phone. "<br>";
//echo $Class. "<br>";
$sql = "INSERT INTO Users
(FirstName, MiddelName, LastName, Username, Password, Email, Phone, Class) VALUES
('$FirstName', '$MiddelName', '$LastName', '$Username', '$Password', '$Email', '$Phone', '$Class')";
$result = mysqli_query($conn, $sql);
header("Location: ../index.php");
?>
The lines i commented out was to test if the data was sent from one page to another, and i did receive the data but when i tried sending it to sql, it didn't reach or didn't get saved there. Can someone help me?
and here is the "PHP/ConfigMamp.php" file:
<?php
$Server = "localhost";
$Username = "root";
$Password = "root";
$Database = "BjerkeWeb";
// Create connection
$conn = mysqli_connect($Server, $Username, $Password, $Database);
// Check connection
// Remove mysqli_connect_error() after testing, leaves vulnerability to sql injection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "<a style='
color: green;
position: absolute;
bottom: 40px;
right: 40px;
'>Connected successfully to the database</a>";
?>