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 socket通信实现多人聊天室疑惑
  • ¥15 DEV-C++编译缺失
  • ¥33 找熟练码农写段Pyhthon程序
  • ¥100 怎么让数据库字段自动更新
  • ¥15 antv g6 力导向图布局
  • ¥15 quartz框架,No record found for selection of Trigger with key
  • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
  • ¥20 MATLAB多目标优化问题求解
  • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
  • ¥15 求一阶微分方程的幂级数