PHP表单没有';不要将数据发送到数据库
我为这个表格问题挣扎了两天。表单做它必须做的一切,除了将数据放入mysql数据库 我正在使用Twitter引导安装Wordpress 这是表单页面:PHP表单没有';不要将数据发送到数据库,php,mysql,wordpress,forms,twitter-bootstrap,Php,Mysql,Wordpress,Forms,Twitter Bootstrap,我为这个表格问题挣扎了两天。表单做它必须做的一切,除了将数据放入mysql数据库 我正在使用Twitter引导安装Wordpress 这是表单页面: <form class="form-inline" role="form" action="../process.php" method="post"> <div class="form-group"> <label class="sr-only" for="email">E-Mail
<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/");
?>
更正语法
$sql="INSERT INTO mailclients (email,voornaam)
VALUES ( '$email','$voornaam' )";
通常我不推荐W3学校,但以下链接足以消除您的疑虑:
像这样使用它,你的mysql\u connect是错误的永远不要在mysql connect中传递所有四个参数如果你想使用它,那么就使用它mysqli\u 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);
谢谢在您的查询中尝试“mailclients”到mailclients,同时检查您是否存在插入(“email”,“voornaam”)
的post值。这些引号应该是backtick,请不要使用mysql函数。使用mysqli或pdo。mysql.*
函数已弃用。使用pdo
或mysqli
。使用mysqli和值(“$email.”、“$voornaam.”)解决问题。或者用backticks@om_deshpande是的,对,但回击不是强制性的,所以为什么要额外头痛:)