dpj83664 2016-03-18 16:57
浏览 29
已采纳

基于URL参数重定向,如果URL参数在表行中可用 - PHP MySQL

I have a table where one of the attribute is version.

The table name is versions.

I want to redirect users to a default page if the URL parameter also called version is NULL or not present, and if the version value is not in my table.

So far I've this. It does not work.

$stonevar = isset($_GET['version']) ? $_GET['version'] : NULL;

if (empty($stonevar)) {
header("Location: index.php?version=default");
 }

$id = $_GET['version'];
$result = $db->query("SELECT * FROM `versions` WHERE version='$id'");

 while ($row = $result->fetch_assoc()) {
  $varex = $row['version'];
 }

if ($varex == NULL) {
header("Location: index.php?default");
}
  • 写回答

2条回答 默认 最新

  • dongshai2022 2016-03-18 17:36
    关注

    You have to add exit(); after header function.

    Try Something like:

      <?php
        $stonevar = isset($_GET['version']) ? $_GET['version'] : NULL;
    
        if (empty($stonevar)) {
        header("Location: index.php?version=default");
        exit();
         }
    
        $result = $db->query("SELECT * FROM `versions` WHERE version='$stonevar'");
    
         while ($row = $result->fetch_assoc()) {
    
        header("Location: index.php?".$row['version']);
        exit();
    /*
    * or something you want to do if version exist
    */
         }
    
        header("Location: index.php?default");
        exit();
        ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler