简体   繁体   English

在链接点击时将枚举值设置为1?

[英]setting enum value to 1 on link click?

can someone please help, i am trying to get the column 'privellages' (i know its spelt wrong) to update in my table 'ptb_permissions' when a link is clicked. 有人可以帮忙吗,当我单击链接时,我正在尝试获取表“ ptb_permissions”中的“特权”列(我知道其拼写错误)。

basically i've done this before for loads of other things and its worked fine its just this not working for some reason. 基本上,我之前已经做过很多其他事情,并且工作正常,只是出于某种原因而没有工作。

users are notified in their inbox when a user sends a request to view their pictures. 当用户发送查看照片的请求时,将在收件箱中通知用户。 and the user will have two links one to approve or one to delete the request. 用户将拥有两个链接:一个要批准,一个要删除请求。

if they click approve then this should update the enum colum 'privellages' from 0 to 1. 如果他们单击批准,则应将枚举列的“特权”从0更新为1。

this is not working. 这是行不通的。 im not getting any errors im just not getting anything happening. 我没有得到任何错误,我只是没有得到任何反应。 please can someone show me where im going wrong thanks. 请有人能告诉我我哪里出错了谢谢。

<a href="includes/approve_priv_pix.php?pix=<?php echo $pix['user_id']; ?>">Yes this is ok</a>

contents of approve_priv_pix.php; approve_priv_pix.php的内容;

<?php
require_once("session.php"); 
require_once("functions.php");
require('_config/connection.php');
approve_pix ($_GET['picture'], $_SESSION['user_id']);
header("Location: {$_SERVER['HTTP_REFERER']}");
?>

mysql function: mysql功能:

function approve_pix($picture, $user) {
                        global $connection;
            global $_SESSION;
                        $query = "UPDATE ptb_permissions
                                    SET privellages='1'
                                    WHERE id=$picture 
                                    AND to_user_id=$user";
            mysql_query($query, $connection);
                }

$_GET['picture'] should be $_GET['pix'] $_GET['picture']应该为$_GET['pix']

Also double check your privellages column enum values. 还要仔细检查您的privellages列枚举值。

<a href="includes/approve_priv_pix.php?pix=<?php echo $pix['user_id']; ?>">Yes this is ok</a>

Here you have pix as a key, but in approve_priv_pix.php you are taking picture id from $_GET['picture'] . 在这里,您将pix作为密钥,但是在approve_priv_pix.php中,您正在从$_GET['picture']获取图片ID。 Suppose it should be replaced with $_GET['pix'] Also, not sure why do you have <?php echo $pix['user_id']; ?> 假设应将其替换为$_GET['pix']此外,不确定为什么会有<?php echo $pix['user_id']; ?> <?php echo $pix['user_id']; ?> in link code. 链接代码中的<?php echo $pix['user_id']; ?> Possibly it should be something like <?php echo $pix['picture_id']; ?> 可能应该像<?php echo $pix['picture_id']; ?> <?php echo $pix['picture_id']; ?>

Additionally, you code is opened to sql injections. 此外,您的代码已打开以进行sql注入。 Here: 这里:

$query = "UPDATE ptb_permissions
          SET privellages='1'
          WHERE id=$picture 
          AND to_user_id=$user";

Instead of that you should better do: 除此之外,您最好执行以下操作:

$query = "UPDATE ptb_permissions
          SET privellages='1'
          WHERE id=" .mysql_real_escape_string($picture) . "
          AND to_user_id=" .mysql_real_escape_string($user);

More details about mysql_real_escape_string . 有关mysql_real_escape_string更多详细信息。 Take a look at warning message on top of that page. 查看该页面顶部的警告消息。 mysql extension is deprecated and will be remove soon. mysql扩展名已弃用,不久将被删除。 For new projects you should better use PDO or MySQLi extensions. 对于新项目,您最好使用PDO或MySQLi扩展。

Another note: global $_SESSION; 另一个说明: global $_SESSION; is not needed at all. 根本不需要。 It is accessible form any place in PHP by default. 默认情况下,可以在PHP中的任何位置访问它。

im not getting any errors im just not getting anything happening 我没有收到任何错误我只是没有得到任何反应

To see all errors you should set error_reporting to E_ALL (in your ini file or directly in code). 要查看所有错误,应将error_reporting设置为E_ALL(在您的ini文件中或直接在代码中)。 With this option enabled you would see all notices/warnings/errors. 启用此选项后,您将看到所有通知/警告/错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM