0
我有一個表單,用戶可以將其聯繫信息(名字,姓氏,電子郵件,電話,網站,評論,託管)提交到數據庫。表單工作正常,直到我嘗試將HTML中的'comment'名稱更改爲'description'。現在,當我提交表單時,php迴應出了響應(因此導致我認爲它正確提交),但是當我在phpMYAdmin中查看錶時,它是空的。SQL查詢正在運行,但隨機停止
數據庫結構是astyle_lefteyebrow>聯繫
表結構:
CustomerID (Primary) int(11)
FirstName text
LastName text
Email varchar (128)
Phone varchar (20) NULL
Website varchar (500) NULL
Description varchar (2000)
Hosting tinyint (1)
PHP文件:
<?php
$servername = "localhost";
$username = "astyle_quiggly";
$password = "**********";
$dbname = "astyle_lefteyebrow";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Check that posts have values
echo $_POST['first_name'];
echo $_POST['last_name'];
echo $_POST['email'];
echo $_POST['phone'];
echo $_POST['website'];
echo $_POST['comment'];
echo $_POST['hosting'];
// prepare and bind
$stmt = $conn->prepare("INSERT INTO Contact (FirstName, LastName, Email, Phone, Website, Description, Hosting) VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssssssi", $firstname, $lastname, $email, $phone, $website, $description, $hosting);
// set parameters and execute
$firstname = $_POST['first_name'];
$lastname = $_POST['last_name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$website = $_POST['website'];
$description = $_Post['comment'];
if ($_POST['hosting'] == 'yes') {
$hosting = 1;}
else {
$hosting = 0;
}
$stmt->execute();
$stmt->close();
$conn->close();
?>
我不知道爲什麼它會被工作,然後所有的突然除非它必須與編碼錯誤有關。有任何想法嗎?
爲什麼你假設你的查詢成功執行('$ stmt-> execute();')?它返回一個布爾值的原因。 – Xorifelse