我正在尝试创建一个将数据提交到mySQL工作台上的数据库的表单。每当我单击提交时,它最终都会下载php文件而不是运行它。所有文件都在同一文件夹中。
inventorylog.html
<form action="insert.php" method="post">
<input required type="text" name="sku_input" placeholder="Sku #" />
<br>
<input value="Add Sku" type="submit" name="submit" />
</form>
connect.php
<?php
$host="localhost";
$port=3306;
$socket="/tmp/mysql.sock";
$user="root";
$password="";
$dbname="Logs";
$con = mysqli_connect($host, $user, $password, $dbname, $port, $socket)
or die ('Could not connect to the database server' . mysqli_connect_error());
//$con->close();
?>
insert.php
<?php
/*Needs the connection object created in the connect.php file to work*/
header("LOCATION:inventorylog.html");
require('connect.php');
/*require('inventorylog.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'])) {
$skunum = mysqli_real_escape_string($con, $_POST['sku_input']);
echo 'sku_input';
$sql = "INSERT INTO skulist (sku_input)
VALUES ('$skunum')";
if ($con->query($sql) === TRUE) {
echo "New record created successfully";
}
else {
echo "Error: " . $sql . "<br>" . $con->error;
}
$con->close();
}
?>