gpt4 book ai didi

PHP - 通过 url id 识别用户

转载 作者:行者123 更新时间:2023-11-29 21:52:14 25 4
gpt4 key购买 nike

我有 3 个按钮来对我的用户进行排名。 Admin , Member和一个禁止它们的按钮。所以现在我想通过它们的“url-id”来识别它们 $_GET 。但是当我这样做时,我收到一个错误:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING).

我该如何解决这个问题?我感谢每一个帮助!

<?php
include_once('connection.php');
if (isset($_POST['ban'])) {
$sql = "UPDATE
t_user_info
SET
user_level = 3
WHERE
id = $_GET['id']";

$query = $conn->prepare($sql);
$query ->execute(array('user_level' => $user_level));

session_unset();
session_destroy();
header('Location: /PHP/index.php?page=ban');
}
if (isset($_POST['admin_btn'])) {
$sql = "UPDATE
t_user_info
SET
user_level = 1
WHERE
id = $_GET['id']";

$query = $conn->prepare($sql);
$query ->execute();
header('Location: /PHP/index.php?page=admin');

}

if (isset($_POST['member_btn'])) {
$sql = "UPDATE
t_user_info
SET
user_level = 2
WHERE
id = $_GET['id']";

$query = $conn->prepare($sql);
$query ->execute();
header('Location: /PHP/index.php?page=member');

}

?>

最佳答案

您的更新查询存在语法错误,并且您没有绑定(bind)正确的值。试试这个:

<?php
include_once('connection.php');
if (isset($_POST['ban'])) {
$sql = "UPDATE
t_user_info
SET user_level = 3
WHERE id = :id";

$query = $conn->prepare($sql);
$query ->execute(array(':id'=>$_GET['id']));

session_unset();
session_destroy();
header('Location: /PHP/index.php?page=ban');
exit;
}

if (isset($_POST['admin_btn'])) {
$sql = "UPDATE
t_user_info
SET user_level = 1
WHERE id = :id";

$query = $conn->prepare($sql);
$query ->execute(array(':id'=>$_GET['id']));
header('Location: /PHP/index.php?page=admin');
exit;
}

if (isset($_POST['member_btn'])) {
$sql = "UPDATE t_user_info
SET user_level = 2
WHERE id = :id";

$query = $conn->prepare($sql);
$query ->execute(array(':id'=>$_GET['id']));
header('Location: /PHP/index.php?page=member');
exit;
}

?>

关于PHP - 通过 url id 识别用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33521792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com