duanhe1976 2013-08-28 06:06
浏览 45
已采纳

从URL验证PHP中的字符串[关闭]

I have a Wordpress site and a front end posting form on it.

When form is submitted, the user gets link to his email with unique string (example 432879374982) saved as a custom field and post gets status "pending":

http://www.mysite.com/verify.php?verify=432879374982

I now want to change status to "published" when user click on a link.

I know that I should use GET parameter, and check if the string is saved in database, and publish the post where there is a match in db, but dont know how to code this.

EDIT:

Made it working!

In the landing page- on wordpress I created a page named "verify" and in template (php) I included code from @Bora- only the database connection has to be established before and it changes the status of a post.

Status has to be set as "publish", not "published"

  • 写回答

1条回答 默认 最新

  • dongxin991209 2013-08-28 06:22
    关注

    Try something like following codes:

    $verify = $mysqli->real_escape_string($_GET['verify']); // escape GET var
    
    $query = "SELECT * FROM table WHERE code = '$verify'"; // Build query
    
    if ($result = $mysqli->query($query)) { // Check return query
    
        while ($row = $result->fetch_assoc()) { // Fetch Row
            $query = "UPDATE table SET status = 'published' WHERE code = '$verify'"; // Update query
            $mysqli->query($query); // Run query
        }
    
        $result->close(); // free result set
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据