首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >HTML & PHP不向MySQL DB表提交数据

HTML & PHP不向MySQL DB表提交数据
EN

Stack Overflow用户
提问于 2015-10-01 21:09:10
回答 1查看 1K关注 0票数 1

我有一个简单的表单和一个将数据提交给MySQL DB的PHP脚本。

一切看起来都很好--我的浏览器正在显示提交的数据 --只是数据没有显示在phpMyAdmin的data中。我看到的只有"MySQL返回一个空结果集(即零行)。“

下面是PHP脚本:

代码语言:javascript
运行
复制
<?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表单:

代码语言:javascript
运行
复制
<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"

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-01 21:13:03

您在SQL查询中缺少一个单引号和一个反勾号。它应该是:

代码语言:javascript
运行
复制
$insqDbtb="INSERT INTO `db594303259`.`House_Leads`
(`PropertyAddress`, `City`, `State`, `ZipCode`, `AskingPrice`, `Name`,
`Phone`, `Email`) VALUES ('$PropertyAddress', '$City', 
'$State', '$ZipCode', '$AskingPrice', '$Name', '$Phone', '$Email')";

(ZipCode漏掉了后勾号,$propertyAddress省略了单引号。)

如果您纠正了这一点,查询可能会工作。

编辑:在phpMyAdmin中试试这个。

代码语言:javascript
运行
复制
INSERT INTO `db594303259`.`House_Leads`
(`PropertyAddress`, `City`, `State`, `ZipCode`, `AskingPrice`, `Name`,
`Phone`, `Email`) VALUES ('test1', 'test2', 
'test3', 'test4', 'test5', 'test6', 'test7', 'test8')

你有什么错误吗?

另外,您可能不需要在查询中再次选择数据库。这样你就可以拥有:

代码语言:javascript
运行
复制
INSERT INTO `House_Leads` ( ...
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32896905

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档