我的阻止用户脚本需要一些帮助。我试图让它插入值,然后将阻止的列设置为从“0”到“1”。
它很好地插入了值,我的意思是它插入了 user_id 和 blocked_id 而没有 prbolem,但是当我尝试将它设置为从“0”到“1”时,它导致语法错误。
谁能告诉我哪里出错了,谢谢。
代码:
<?php
require_once('includes/session.php');
require_once('includes/functions.php');
require('includes/_config/connection.php');
session_start();
confirm_logged_in();
if (isset ($_GET['to'])) {
$user_to_id = $_GET['to'];
}
if (!isset($_GET['to']))
exit('No user specified.');
$user_id = $_GET['to'];
$result1 = mysql_query("INSERT INTO ptb_block_user (user_id, blocked_id) VALUES (".$_SESSION['user_id'].", ".$user_to_id.")")
$result2 = mysql_query("SELECT ptb_block_user SET blocked='1' WHERE id=".$_SESSION['user_id']."")
or $result3 = mysql_query("DELETE FROM ptb_block_user WHERE user_id = ".$_SESSION['user_id']." AND blocked_id = ".$user_to_id.""); header("Location: {$_SERVER['HTTP_REFERER']}");
if($result1)
{
$_SESSION['message2']="<div class=\"infobox-profile\"><strong>User Blocked</strong> - This user has successfully been blocked. You will no longer be abler to interact with each other's profiles.</div><div class=\"infobox-close\"></div>";
header("Location: {$_SERVER['HTTP_REFERER']}");
}
else
if($result3)
{
$_SESSION['message2']="<div class=\"infobox-favourites\"><strong>User Unblocked</strong> - This user has successfully been unblocked. You can now interact with each other's profiles.</div><div class=\"infobox-close4\"></div>";
header("Location: {$_SERVER['HTTP_REFERER']}");
}
?>
最佳答案
$result2 = mysql_query("UPDATE ptb_block_user SET blocked='1' WHERE id=".$_SESSION['user_id']."")
使用“更新”而不是“选择”来更改行。
关于php - 获取插入到 mysql 中的值并设置从 '0' 到 '1' 的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14637541/