有人可以解释为什么这个插页不起作用吗?
if(isset($_POST['send'])){
$query = 'INSERT INTO subsciber(data, ip, email)
VALUES(CURRENT_TIMESTAMP, "'.$_SERVER['REMOTE_ADDR'].'", "'.$_POST['email'].'")';
$result = @mysqli_query($dbc, $query);
}
表单代码如下所示:
<div class="row">
<div class="col-md-4 col-md-offset-4 col-sm6-6 col-sm-offset-3 ">
<form class="form-inline" role="form" method="post">
<div class="form-group">
<label class="sr-only" for="exampleInputEmail2">Email address</label>
<input name='email' id="email" type="email" class="form-control transparent" placeholder="Your email here...">
</div>
<button type="submit" name='send' value='send' class="btn btn-danger btn-fill">Notify Me</button>
</form>
</div>
</div>
答案 0 :(得分:1)
您应该包含mysqli
error
function
以查看错误
if(isset($_POST['send'])){
$query = 'INSERT INTO subsciber(data, ip, email)
VALUES(CURRENT_TIMESTAMP, "'.$_SERVER['REMOTE_ADDR'].'", "'.$_POST['email'].'")';
//echo $query; to see query output
$result = mysqli_query($dbc, $query) or die(mysqli_error($dbc));
}
同样data
是mysqli keyword
所以请在此处使用backtick
$query = 'INSERT INTO subsciber(`data`, ip, email)
VALUES(CURRENT_TIMESTAMP, "'.$_SERVER['REMOTE_ADDR'].'", "'.$_POST['email'].'")';
答案 1 :(得分:-1)
您的表单没有操作属性:
这样做:
<form action="the url to your PHP script">
答案 2 :(得分:-2)
替换
@mysqli_query($dbc, $query);
与
mysqli_query($dbc, $query);
答案 3 :(得分:-2)
而不是单引号,您可以使用doublequotation
试试这个
if(isset($_POST["send"])) {
.....
}