与令牌数量不匹配

时间:2018-01-16 14:27:47

标签: php html sql database

我有一个用户可以发送反馈的页面,但是当我点击发送时,我收到错误并显示:

Error

这是我的insert-message.php:

<?php
require_once ('database.php');

if (isset($_POST['send'])) {

$employee_id = $_POST['employee_id'];
$full_name = $_POST['full_name'];
$email = $_POST['email'];
$website = ($_POST['website']);
$message = ($_POST['message']);

{
$database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$insert_query = "INSERT INTO tbl_feedback (employee_id, full_name, email, website, message)
VALUES (?, ?, ?, ?)";

$insert = $database->prepare($insert_query);
$insert->execute(array($employee_id, $full_name, $email, $website, $message));

echo "<script>alert('Successfully sent!'); window.location='feedback.php'</script>";
}
}
?>

这是我的表格:

<div class="row">
	<div class="col-xs-6">
		<form method="post" action="insert-message.php">
			<div class="form-group">
				<label for="exampleInputPassword1">Employee ID<span style="color:#d0d0d0;"> (required)</span></label>
				<input type="text" readonly="readonly" class="form-control" name="employee_id" value="<?php echo $user_id; ?>" autofocus="autofocus" required />
			</div>
			<div class="form-group">
				<label for="exampleInputPassword1">Name<span style="color:#d0d0d0;"> (required)</span></label>
				<input type="text" readonly="readonly" class="form-control" name="full_name" value="<?php echo $fullname; ?>" autofocus="autofocus" required />
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1">Email Address <span style="color:#d0d0d0;">(required)</span></label>
				<input type="email" class="form-control" name="email" required />
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1">Website</label>
				<input type="text" class="form-control" name="website">
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1">Your Message <span style="color:#d0d0d0;">(required)</span></label>
				<textarea class="form-control" name="message" style="height:200px;" required ></textarea>
			</div>
			
			<a href="home"><button type="button" class="btn btn-primary"><i class="glyphicon glyphicon-arrow-left"></i> Back</button></a>
			<button type="submit" name="send" class="btn btn-primary"><i class="glyphicon glyphicon-send"></i> Send</button>
			
		</form>
	</div>
</div>

表单工作正常,这只是我点击发送时的错误。另外,我的数据库中有2个表,反馈和员工。 “employee_id”充当employee表中引用“id”的外键。

我不确定你们是否需要这些,但我不妨补充一下这些信息。

1 个答案:

答案 0 :(得分:0)

您的查询VALUES (?, ?, ?, ?)";中只有4个占位符,但您绑定了5个值。您还在查询中指定了5列。我想你错过了一个额外的问号。