Can not Insert data into MySQL from PHP form

After I fill up the PHP form, the data is not showing in mysql. What is wrong with my code and how can i fix it?

These are all my codes. Please help me I am still a beginner in php. I tried searching my error in other websites however it is not working.

This is the code for the form index.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
  <!-- C R E A T E  D A T A -->
  <form class="" action="createdatatry.php" method="post">
    <h3>ENTER THE FOLLOWING SUPPLIER INFORMATION:</h3>
    <input type="text" name="Supplier_Name" placeholder="Enter Supplier Name" required/>
    <input type="text" name="Supplier_Contact" placeholder="Enter Contact No." required/>
    <input type="text" name="Supplier_StreetNo" placeholder="Enter Street No." required/>
    <input type="text" name="Supplier_Province" placeholder="Enter Province" required/>
    <input type="text" name="Supplier_PostalCode" placeholder="Enter Postal Code" required/>
    <input type="text" name="Supplier_Country" placeholder="Enter Country" required/>
    <input type="submit" name="create" value="CREATE">
  </form>
</body>
</html> 

This is the code for the mysql connection database.php

<?php
    
$host = 'localhost';
$user = 'root';
$password = '';
$database = 'sourcingdb';

$connection = mysqli_connect($host, $user, $password, $database);

if (mysqli_connect_error()) {
    echo "Error Unable to connect to MySQL server <br>";
    echo "Message: ".mysqli_connect_error()."<br>";
} 


?>

This is the code in creating/ inserting data into mysql createdatatry.php

<?php

require('./database.php');

if (isset($_POST['create'])) {
    $Supplier_Name = $_POST['Supplier_Name'];
    $Supplier_Contact = $_POST['Supplier_Contact'];
    $Supplier_StreetNo = $_POST['Supplier_StreetNo'];
    $Supplier_Prov = $_POST['Supplier_Prov'];
    $Supplier_PostalCode = $_POST['Supplier_PostalCode'];
    $Supplier_Country = $_POST['Supplier_Country'];

    $queryCreate = "INSERT INTO supplierinfo (`Supplier_Name`, `Supplier_Contact`, `Supplier_StreetNo`, `Supplier_Province`, `Supplier_PostalCode`, `Supplier_Country`) VALUES ('$Supplier_name', '$Supplier_Contact', '$Supplier_StreetNo', '$Supplier_Prov', '$Supplier_PostalCode', '$Supplier_ountry')";
    $sqlCreate = mysqli_query($connection, $queryCreate);

    echo '<script>alert("Successfully created!")</script>';
    //echo '<script>window.location.href = "/sourcing/index.php"</script>';
}

?>


Read more here: https://stackoverflow.com/questions/67378708/can-not-insert-data-into-mysql-from-php-form

Content Attribution

This content was originally published by Carrington at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: