dpnw86361 2012-11-01 15:30
浏览 17
已采纳

PHP中的基本SQL Update查询

I am using a MVC framework and have a problem in a SQL query.

The user that publish a post on my website receives an email containing a confirmation 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)

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.

    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 !

  • 写回答

2条回答 默认 最新

  • dor65412 2012-11-01 15:32
    关注

    There's no WHERE clause in your UPDATE command.

    db::query('UPDATE `'.DB_PREFIX.'.Posts` SET `published`=1 WHERE id = ' . $row['id'] );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测