duanping2695 2015-12-13 07:53
浏览 44
已采纳

条件中的$ _GET变量

I am struggling a bit with this one. I have this function called getCategories:

Hi. I am struggling a bit with this one. I have this

function getCategories(){
    global $con;
    $q = "SELECT * FROM categories;";
    $result = mysqli_query($con, $q);
    while($row = mysqli_fetch_assoc($result)){
        $category = $row["CategoryName"];
        $sec = htmlspecialchars($category);
        echo " <tr>
        <td>" . $category . "</td>
        <td>
            <a>View</a> |
            <a href=categories.php?task=update&category=" . urlencode($category) . ">Edit</a> |
            <a href=categories.php?task=delete&category=" . urlencode($category) . ">Delete</a>
        </td>
        </tr>";
    }
}

then I have categories.php (the form)

<form action="categories.php" method="POST">
    <p>
        <label for="categoryname">Category Name:&nbsp;</label>
        <input type="text" name="category_name" placeholder="Enter category name" value="<?php echo $editCat?>">
        <?php
            if ($_GET["task"]="") {
                echo "<input type='submit' value='Add Category' name='submit'>";
            } else {
                echo "<input type='submit' value='Update Category' name='update'>";
            }           
        ?>
    </p>
</form>

But when I click the edit button, the script always echo the first one. What should I do?

  • 写回答

3条回答 默认 最新

  • dongtan7998 2015-12-13 08:11
    关注

    You can check if task variable is passed in url as query string or not.

    <?php
        if (!isset($_GET["task"]) || $_GET["task"] == '') {
            echo "<input type='submit' value='Add Category' name='submit'>";
        } else {
            echo "<input type='submit' value='Update Category' name='update'>";
        }           
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教