【发布时间】:2015-12-09 11:05:11
【问题描述】:
我有以下引导联系表:
<form role="form">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
<input type="text" class="form-control" placeholder="First Name" name="firstname" id="firstname" value="<?php echo $_POST['firstname']; ?>">
</div>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
<input type="text" class="form-control" placeholder="Family Name" name="familyname" id="familyname" value="<?php echo $_POST['familyname']; ?>">
</div>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-earphone"></span></span>
<input type="text" class="form-control" placeholder="Phone Number" name="phone" id="phone" value="<?php echo $_POST['phone']; ?>">
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary" onclick="">Submit</button>
<input type="hidden" name ="mode" value="submit">
</div>
</form>
在提交时,我想插入如下联系表:
if (($_POST['mode']) == 'submit'){
var_dump("Testing if I entered this if statement"); die();
$add_contact = mysqli_query($conn, "INSERT INTO `contact` (
`cont_id`, //it is auto increment id
`cont_fname`,
`cont_family`,
`cont_phone`
) VALUES (
'" . $_POST['firstname'] . "',
'" . $_POST['familyname'] . "',
'" . $_POST['phone'] . "'
)") or die(mysqli_error($conn));
}
我遇到了两个问题。首先点击提交按钮后,程序没有进入if语句?其次,数据库插入有什么问题?我尝试在不同的脚本中插入,但它不起作用。如果您能提供帮助,我将不胜感激。
这是我的连接文件,它工作正常,这意味着我连接到我的数据库:
$conn=mysqli_connect("localhost","contacts");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
【问题讨论】:
-
if(isset($_POST['formname'])){......#enter your code here}..给出形成POST的方法 -
使用 post 方法后工作,但它不插入数据库,知道为什么吗?
-
设置
name和value属性提交按钮和删除隐藏字段。
标签: php twitter-bootstrap