我在这个表格问题上苦苦挣扎了两天。除了将数据放在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/");
?>
我希望有人可以帮助我!提前谢谢。
托马斯
答案 0 :(得分:0)
更正语法
$sql="INSERT INTO mailclients (email,voornaam)
VALUES ( '$email','$voornaam' )";
通常我不推荐W3school,但以下链接足以消除您的疑虑: http://www.w3schools.com/php/php_mysql_insert.asp
答案 1 :(得分:0)
像这样使用它,你的mysql_connect是错误的,如果你想使用它,那么永远不会传递mysql connect中的所有四个参数然后使用它mysqli_connect
$voornaam=$_POST["voornaam"];
$email=$_POST["email"];
//establish connection
$con = mysqli_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' )";
mysqli_query($con,$sql);
由于