【发布时间】:2013-11-25 12:44:49
【问题描述】:
我为这个表单问题苦苦挣扎了两天。除了将数据放入 mysql 数据库之外,该表单会执行它必须执行的所有操作。
我正在使用 Twitter Bootstrap 安装 Wordpress。
这是表单页面:
<form class="form-inline" role="form" action="../process.php" method="post">
<div class="form-group">
<label class="sr-only" for="email">E-Mail</label>
<input type="email" name="email" class="form-control" id="email" placeholder="E-Mail">
</div>
<div class="form-group">
<label class="sr-only" for="voornaam">Voornaam</label>
<input type="text" name="voornaam" class="form-control" id="voornaam" placeholder="Voornaam">
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-default">Schrijf me in!</button>
</div>
</form>
这是process.php:
<?php
//get the form elements and store them in variables
$voornaam=$_POST["voornaam"];
$email=$_POST["email"];
//establish connection
$con = mysql_connect("localhost","user","pasw","db"); //actual names in my code
//on connection failure, throw an error
if(!$con) {
die('Could not connect: '. mysql_error());
}
$sql="INSERT INTO 'mailclients' ( 'email' , 'voornaam' )
VALUES ( '$email','$voornaam' )";
mysql_query($con,$sql);
//Redirects to the specified page
header("Location: /nieuwsbrief-bedankt/");
?>
我希望有人可以在这里帮助我!提前致谢。
托马斯
【问题讨论】:
-
在您的查询中尝试 'mailclients' 到 mailclients 并检查您是否存在用于插入的 post 值
-
( 'email' , 'voornaam' )这些引号应该是反引号 -
请不要使用mysql_*函数。使用 mysqli 或 pdo。
-
mysql_*函数已弃用。使用PDO或mysqli。 -
感谢大家的 mysqli 和 VALUES ('" . $email . "','" . $voornaam . "') 解决了它。
标签: php mysql wordpress forms twitter-bootstrap