因此,我正在尝试创建一个HTML表单,它将数据发布到MySQL中使用PHP的客户数据库中,但对于PHP来说却很新颖。PHP:使用HTML表单在MySQL Workbench中写入数据库6.3
目前,只要我尝试使用提交按钮“在此服务器上未找到请求的URL/bankyprinting/post”提交所有内容,我就会收到404。数据也没有被注入到MySQL数据库中,但是我没有收到任何其他错误,表明没有连接到数据库。
我试图写/使用的应用程序是:
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();
?>
和 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();
}
?>
我已经得到了所有这些存储在由WAMP服务器 - 托管的文件夹是的,我已经知道HTML表单并不稳固,但是这是我的问题的权利范围之外现在> <。
我不知道为什么我会得到PHP错误(POST错误?),我不知道如何通过获取表单以正确注入数据库来解决这个问题。
他们都在同一个文件夹?这四个文件? –
用引号括起变量'''''''Customer'' – Shehary
你不能在html中包含php文件,就像你写的** bankyprinting.html ** – Joomler