So I'm attempting to create an html form that posts data to a database full of customers in MySQL using PHP, but am very new to PHP.
Currently, I'm getting a 404 whenever I try to submit everything with the submit button "The requested URL /bankyprinting/post was not found on this server." The data is also not injected into the MySQL database, but I'm not getting any other errors indicating that the connection to the database wasn't made.
The applications I'm attempting to write/use are:
customers.html
<html>
<head>
</head>
<body>
<form method = "post" action = "customers.php" id="customers">
First Name:
<input type = "text" name = "FirstName"/><br>
LastName:
<input type = "text" name = "LastName"/><br>
Company:
<input type = "text" name = "Company"/><br>
Position:
<input type = "text" name = "Position"/><br>
Address:
<input type = "text" name = "Address"/><br>
Phone Number:
<input type = "text" name = "PhoneNumber"/><br>
Cell Number:
<input type = "text" name = "CellNumber"/><br>
Alternate Number:
<input type = "text" name = "AlternateNumber"/><br>
E-Mail:
<input type = "text" name = "EMail"/><br>
<input type = "submit" name="submit" value = "submit"/><br>
</form>
</body>
<footer>
</footer>
</html>
index.html
</html>
<head>
</head>
<body>
<a href = "customers.html">New Customer</a>
</body>
<footer>
</footer>
</html>
connect.php
<?php
$host="localhost";
$port=3306;
$socket="/tmp/mysql.sock";
$user="root";
$password="";
$dbname="bankyprinting";
$con = mysqli_connect($host, $user, $password, $dbname, $port, $socket)
or die ('Could not connect to the database server' . mysqli_connect_error());
//$con->close();
?>
and customers.php
<?php
/*Needs the connection object created in the connect.php file to work*/
header("LOCATION:customers.html");
require('connect.php');
/*require('customers.html');*/
/*Data from the html form is on the right. The objects that will be composed of that data is on the left.*/
if(isset($_POST['submit'])) {
$Company = mysqli_real_escape_string($con, $_POST['Company']);
echo 'Company';
$Position = mysqli_real_escape_string($con, $_POST['Position']);
echo 'Position';
$FirstName= mysqli_real_escape_string($con, $_POST['FirstName']);
echo 'FirstName';
$LastName = mysqli_real_escape_string($con, $_POST['LastName']);
echo 'LastName';
$Address = mysqli_real_escape_string($con, $_POST['Address']);
echo 'Address';
$PhoneNumber = mysqli_real_escape_string($con, $_POST['PhoneNumber']);
echo 'PhoneNumber';
$CellNumber = mysqli_real_escape_string($con, $_POST['CellNumber']);
echo 'CellNumber';
$AlternateNumber = mysqli_real_escape_string($con, $_POST['AlternateNumber']);
echo 'AlternateNumber';
$EMail = mysqli_real_escape_string($con, $_POST['Email']);
echo 'EMail';
$sql = "INSERT INTO tblcustomers (Company, Position, FirstName, LastName, Address, PhoneNumber, CellNumber, AlternateNumber, EMail)
VALUES ('$Customer', '$Position', '$FirstName', '$LastName', '$Address', '$PhoneNumber', '$CellNumber', '$AlternateNumber', '$EMail')";
if ($con->query($sql) === TRUE) {
echo "New record created successfully";
}
else {
echo "Error: " . $sql . "<br>" . $con->error;
}
$con->close();
}
?>
I've got all of these stored on a folder hosted by a WAMP server- and yes I already know that the html forms are not secured- but that's outside the scope of my problem right now ><.
I don't know exactly why I'm getting the PHP error (POST error?) and am not sure how to address that by getting the form to inject into the database properly.