我无法弄清楚这里出了什么问题。我有 Bootstrap 3.0。
我的form.php
<form role="form" action="../../sgm/leadinsert" method="post">
<div class="form-group">
<label for="fName">First Name</label>
<input type="text" class="form-control" id="fName" name="fName" placeholder="Enter first name" />
</div>
<div class="form-group">
<label for="lName">Last Name</label>
<input type="text" class="form-control" id="lName" name="lName" placeholder="Enter last name" />
</div>
<div class="form-group">
<label for="pNo">Phone Number</label>
<input type="text" class="form-control" id="pNo" name="pNo" placeholder="Ex: 555-555-5555" />
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" name="email" placeholder="example@gmail.com" required />
</div>
<div class="form-group">
<label for="comm">Comments</label>
<textarea class="form-control" rows="3" id="comm" name="comm" placeholder="Enter any comments here; max size 500 chars."></textarea>
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn btn-default" value="Next"/>
</div>
</form>
这是我的leadinsert.php
<?php
$con=mysqli_connect("localhost","user","pass","db");
$fName = $_POST[ "fName" ];
$lName = $_POST[ "lName" ];
$pNo = $_POST[ "pNo" ];
$email = $_POST[ "email" ];
$comm = $_POST[ "comm" ];
$sql="INSERT INTO Leads (fName, lName, pNo, email, comm)
VALUES ('$fName', '$lName', '$pNo', '$email', '$comm')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con) . print_r($_POST));
}
echo "1 record added";
mysqli_close($con);
?>
注意:在我的操作中=我设置了 .htaccess 来解释它。在我实现 Bootstrap 之前,将表单提交到我的数据库从来没有遇到过问题。它正在提交到我的数据库表,但它是一个空行。
最佳答案
安装 Bootstrap 不会对您处理表单的方式产生任何影响,因为 Bootstrap 只是 css 和 javascript 的模板。我会在您的 insert.php 中进行一些检查,例如 issets,并查看帖子中是否确实有任何信息。您还可以在 Chrome 开发者控制台中进行检查。
关于PHP $_POST vars 为空,Bootstrap 表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21774064/