我確信這已被詢問了1000次,但我已經查看了所有內容,似乎無法使其工作。如何將Web窗體中的數據傳輸到數據庫
形式:
<form action="sendinfo.php" method="post">
<h4>ID:</h4>
<input type="text" name="CustomerID">
<h4>First name:</h4>
<input type="text" name="FirstName">
<h4>Last Name:</h4>
<input type="text" name="LastName">
<h4>Street:</h4>
<input type="text" name="Street">
<h4>City:</h4>
<input type="text" name="City">
<h4>Zip:</h4>
<input type="text" name="Zip">
<h4>State:</h4>
<input type="text" name="State">
<h4>Phone:</h4>
<input type="text" name="Phone">
<h4>Email:</h4>
<input type="text" name="Email">
<input type="submit">
</form>
sendinfo.php
<?php
include('connection.php');
$dbh = con();
$dbh->query = "INSERT INTO Customer (CustomerID, FirstName, LastName, Street, City, State, Zip, Phone, Email)
VALUES ('$_POST[CustomerID]', ('$_POST[FirstName]', ('$_POST[LastName]', ('$_POST[Street]', ('$_POST[City]', ('$_POST[State]', ('$_POST[Zip]', ('$_POST[Phone]', ('$_POST[Email]')";
if (!mysql_query($user_info, $connect)) { die('Error: ' . mysql_error()); } echo 「Your information was added to the database.」; mysql_close($connect);
?>
connection.php
<?php
define("DB_HOST", "localhost");
define("DB_NAME", "Impact_Technologies");
define("DB_USER", "root");
define("DB_PASS", "password");
function con(){
try {
$db_connection = new PDO('mysql:host='. DB_HOST .';dbname='. DB_NAME . ';charset=utf8', DB_USER, DB_PASS);
return $db_connection;
} catch (PDOException $e) {
echo "Sorry, there was a problem connecting to the database." . $e->getMessage();
}
}
?>
當點擊提交後,沒有消息顯示,並進入數據庫沒有信息
該死的複製粘貼哈哈。我發現了另一件事加上你說的和它的工作!非常感謝! – Randy
非常歡迎,請將答案標爲正確:)! –