简体   繁体   English

PHP中的基本SQL更新查询

[英]Basic SQL Update query in PHP

I am using a MVC framework and have a problem in a SQL query. 我正在使用MVC框架,并且在SQL查询中有问题。

The user that publish a post on my website receives an email containing a confirmation URL : 在我的网站上发布帖子的用户会收到一封包含确认URL的电子邮件:

mywebsite.com/confirm/f9b83b3bf994e5db3b06ya20eb306a24/

The routing is made correctly, but I would like to change the SQL "published" field to 1 (it is set to 0 by default) 路由正确完成,但我想将SQL“已发布”字段更改为1(默认情况下设置为0)

So basically, everything is working except my UPDATE SQL query, it's probably something stupid but I am a beginner in this domain and I couldn't fix it after many tries. 因此,基本上来说,除了我的UPDATE SQL查询之外,其他所有东西都可以正常工作,这可能有点愚蠢,但我是该领域的初学者,经过多次尝试后无法修复。

    if(substr(ROUTE, 0, 8) == 'confirm/')
        {
            if(strlen($code = substr(ROUTE, 8, 32)) == 32)
            {
                if($row = db::fetch(db::query('SELECT `id` FROM `'.DB_PREFIX.'Posts` WHERE `published`=0 AND `confirm`="'.db::escape($code).'"'), 'row'))
                {

//This is the problematic line
                 db::query('UPDATE '.DB_PREFIX.'Posts SET published=1 WHERE published=0 AND confirm="'.db::escape($code).'"');

                }
            }

            header('Location: '.WEB.'publish_success.html');
        } 

Thank youf or your help :) 谢谢您的帮助 :)

Edit : Problem fixed adding the WHERE clause ! 编辑:问题解决了添加WHERE子句!

您的UPDATE命令中没有WHERE子句。

db::query('UPDATE `'.DB_PREFIX.'.Posts` SET `published`=1 WHERE id = ' . $row['id'] );

Can you please try the below query. 能否请您尝试以下查询。 I don't know exactly whether it will work or not. 我不确切知道它是否会工作。

  db::query("UPDATE `".DB_PREFIX."Posts` SET `published`=1 WHERE `published`=0 AND `confirm`='".db::escape($code)."'");

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

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