我正在编写一个代码,在其中放置信息并将信息发送到数据库,但是由于我遇到无法修复的错误,因此它不发送信息:
解析错误:语法错误,第21行的代码中出现意外的';',预期为','或')'
我已经尽力了,但无法解决。
信息应该发送到数据库,但是由于错误,它不起作用
<?php
require_once "../config.php";
$mysqli->set_charset("utf8");
if (isset($_POST["name"]) && isset($_POST["value"]) && isset($_POST["pk"]) && strlen($_POST["value"]) > 2) {
$mysqli->query("UPDATE events set " . $mysqli->real_escape_string($_POST['name']) . "='" . $mysqli->real_escape_string($_POST['value']) . "' where id='" . $mysqli->real_escape_string($_POST["pk"]) . "'");
if ($mysqli->affected_rows > 0) {
echo $mysqli->real_escape_string($_POST['value']);
} else {
echo "<div class='alert alert-danger'>Failed to Perform Operation " . $mysqli->error . "</div>";
}
} else
if (isset($_POST["eventname"]) && isset($_POST["date"]) && isset($_POST["seats"]) && isset($_POST["typeto"])) {
$checkToInsert = $mysqli->query("SELECT id from events where eventname='" . $mysqli->real_escape_string($_POST["eventname"]) . "' && date='" . $mysqli->real_escape_string($_POST["date"]) . "' && seats='" . $mysqli->real_escape_string($_POST["seats"]) . "'");
if ($checkToInsert->num_rows < 1) {
$mysqli->query("INSERT INTO events (price, phone, contact, eventdesc, address, eventname, date, dateto, seats, typeto, time, endtime)
VALUES ('" . $mysqli->real_escape_string($_POST["price"]) . "' , '" . $mysqli->real_escape_string($_POST["phone"]) . "' , '" . $mysqli->real_escape_string($_POST["contact"]) . "', '" . $mysqli->real_escape_string($_POST["eventdesc"]) . "', '" . $mysqli->real_escape_string($_POST["address"]) . "', '" . $mysqli->real_escape_string($_POST["eventname"]) . "','" . $mysqli->real_escape_string($_POST["date"]) . "', '" . $mysqli->real_escape_string($_POST["dateTo"]) . "', '" . $mysqli->real_escape_string($_POST["seats"]) . "','" . $mysqli->real_escape_string($_POST["typeto"]) . "', '00:00', '00:00');";
//The error is in this area
if ($mysqli->affected_rows > 0) {
echo "<div class='alert alert-success'>Successfully Perform Operation</div>";
} else {
echo "<div class='alert alert-danger'>Failed to Perform Operation " . $mysqli->error . "</div>";
}
} else {
echo "<div class='alert alert-danger'>Oh! Snap Value is already available</div>";
}
} else
if (isset($_POST["pk"]) && isset($_POST["delete"]) && $_POST["delete"] == "true") {
$mysqli->query("DELETE from events where id='" . $mysqli->real_escape_string($_POST["pk"]) . "'");
if ($mysqli->affected_rows > 0) {
echo "<div class='alert alert-success'>Successfully Perform Operation</div>";
} else {
echo "<div class='alert alert-danger'>Failed to Perform Operation " . $mysqli->error . "</div>";
}
} else {
echo "<div class='alert alert-danger'>Kindly fill all the form properly</div>";
} ?>
答案 0 :(得分:-1)
我认为错误可能是由您的评论上方一行中的)
错误引起的:
. $mysqli->real_escape_string($_POST["typeto"]) . "', '00:00', '00:00');");
<=此处。
答案 1 :(得分:-1)
错误在您的mysqli查询中的代码的第21行:
$mysqli->query(
"INSERT INTO events (
price,
phone,
contact,
eventdesc,
address,
eventname,
date,
dateto,
seats,
typeto,
time,
endtime
) VALUES (
'" . $mysqli->real_escape_string($_POST["price"]) . "' , '" .
$mysqli->real_escape_string($_POST["phone"]) . "' , '" .
$mysqli->real_escape_string($_POST["contact"]) . "', '" .
$mysqli->real_escape_string($_POST["eventdesc"]) . "', '" .
$mysqli->real_escape_string($_POST["address"]) . "', '" .
$mysqli->real_escape_string($_POST["eventname"]) . "','" .
$mysqli->real_escape_string($_POST["date"]) . "', '" .
$mysqli->real_escape_string($_POST["dateTo"]) . "', '" .
$mysqli->real_escape_string($_POST["seats"]) . "','" .
$mysqli->real_escape_string($_POST["typeto"]) . "',
'00:00', '00:00'
);";
您缺少右括号(请参见下文)
$mysqli->query(
"INSERT INTO events (
price,
phone,
contact,
eventdesc,
address,
eventname,
date,
dateto,
seats,
typeto,
time,
endtime
) VALUES (
'" . $mysqli->real_escape_string($_POST["price"]) . "' , '" .
$mysqli->real_escape_string($_POST["phone"]) . "' , '" .
$mysqli->real_escape_string($_POST["contact"]) . "', '" .
$mysqli->real_escape_string($_POST["eventdesc"]) . "', '" .
$mysqli->real_escape_string($_POST["address"]) . "', '" .
$mysqli->real_escape_string($_POST["eventname"]) . "','" .
$mysqli->real_escape_string($_POST["date"]) . "', '" .
$mysqli->real_escape_string($_POST["dateTo"]) . "', '" .
$mysqli->real_escape_string($_POST["seats"]) . "','" .
$mysqli->real_escape_string($_POST["typeto"]) . "',
'00:00', '00:00'
)");
答案 2 :(得分:-1)
大约20分钟前,我已经在对该问题的评论中张贴了导致此问题的原因。但是很显然,您很难找到它。因此,这里有一个更明确的指向:
您当前的第21行是:
$mysqli->query("INSERT INTO events (...) VALUES (...);";
它需要query()
方法的附加右括号,如下所示:
$mysqli->query("INSERT INTO events (...) VALUES (...);");
这就是为什么它在代码中显示“意外的';',期望为','或')'...
;-)