我已經有一個簡單的HTML聯繫表單和一個PHP腳本來提交數據到MySQL數據庫。HTML表單&PHP腳本 - 沒有提交數據到MySQL數據庫表
一切似乎工作正常 - 我的瀏覽器顯示the data was submitted - 除了數據不顯示在phpMyAdmin的數據庫表中。我看到的是"MySQL returned an empty result set (i.e. zero rows)."
這裏是PHP腳本:
<?php
$link = mysqli_connect("db.example.com","dbo","*********") or die("failed to connect to server !!");
mysqli_select_db($link,"db");
if(isset($_REQUEST['submit']))
{
$errorMessage = "";
$PropertyAddress=$_POST['PropertyAddress'];
$City=$_POST['City'];
$State=$_POST['State'];
$ZipCode=$_POST['ZipCode'];
$AskingPrice=$_POST['AskingPrice'];
$Name=$_POST['Name'];
$Phone=$_POST['Phone'];
$Email=$_POST['Email'];
// Validation will be added here
if ($errorMessage != "") {
echo "<p class='message'>" .$errorMessage. "</p>" ;
}
else{
//Inserting record in table using INSERT query
$insqDbtb="INSERT INTO `db`.`House_Leads`
(`PropertyAddress`, `City`, `State`, `ZipCode, `AskingPrice`, `Name`,
`Phone`, `Email`) VALUES ('$PropertyAddress, '$City',
'$State', '$ZipCode', '$AskingPrice', '$Name', '$Phone', '$Email')";
mysqli_query($link,$insqDbtb) or die(mysqli_error($link));
}
}
?>
這裏是我的HTML表單:
<form role="form" action="houseleads.php" method="POST" class="contact clearfix">
<p class="text _text text-4">Property Information</p>
<input class="_input _input-1" name="PropertyAddress" placeholder="Property Street Address" type="text">
<div class="container container-2 clearfix">
<input id="city" class="_input" name="City" placeholder="City" type="text">
<input id="state" class="_input _input-3" name="State" placeholder="State" type="text">
</div>
<div class="container container-3 clearfix">
<input id="zipcode" class="_input" name="ZipCode" placeholder="Zip Code" type="text" maxlength="5">
<input id="price" class="_input _input-5" name="AskingPrice" placeholder="Your Asking Price" type="number" step="5000">
</div>
<p class="text _text text-5">Contact Information</p>
<div class="container container-4 clearfix">
<input id="name" class="firstname" name="Name" placeholder="Your Name" type="text">
<input id="phone" class="_input _input-6" name="Phone" placeholder="Phone Number" type="tel" maxlength="10">
</div>
<input id="email" class="_input _input-7" name="Email" placeholder="Email Address" type="email">
<button id="submit" class="_button" type="submit">Get an Offer</button>
</form>
任何幫助或洞察力,將不勝感激。這是我第一次嘗試使用PHP,經過幾個小時的努力之後,X)我不知所措。
編輯:隨着克里斯認定的缺少反引號 - 我錯過了表單按鈕的HTML中的name="submit"
。
請查閱準備好的語句。你不想直接從$ _POST插入。這將非常有幫助。 –
好的,謝謝。會做。 –
回顯'$ insqDbtb'並看看你得到了什麼。 –