我正在尝试在php中运行查询,如下所示:
<?php
$email = mysql_real_escape_string($_POST['email']);
if(isset($_POST['savedata'])){
$sql = "INSERT INTO registered (email)
VALUES (
'$email'
)";
$result = mysql_query($sql);
if(!$result){
echo 'something went wrong, please try again.';
echo mysql_error();
} else {
echo '<meta http-equiv="refresh" content="2; url = subscribed.php" />';
}
}
?>
执行的触发器来自以下形式:
<form action="" method="post">
<div class="form-group">
<label class="sr-only" for="exampleInputEmail2">Email address</label>
<input type="email" name="email" id="email" class="form-control transparent" placeholder="Your email here...">
</div>
<input type="submit" name="submit" class="btn btn-warning btn-fill">Notify Me</input>
<input type="hidden" name="savedata" value="savedata"/>
</form>
这在phpMyAdmin中运行良好(当然我将$ email更改为真实地址)但除了刷新之外没有任何事情发生在php中。数据库没有更新,我检查了连接 - 它正在工作。 请指教。 谢谢!
答案 0 :(得分:1)
尝试以下查询:
$sql = "INSERT INTO registered (email)
VALUES (
'".$email."'
)";