因此,我正在嘗試創建一個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