doutang7415 2017-01-18 10:22
浏览 69
已采纳

php按钮值问题

I am brand new to PHP and have run into an issue with my buttons in a table. When the button is clicked, it needs to get an ID number that is pulled from a database. I have no trouble getting the data and passing it to the next page using...

<form action="ThisPage.php" method="post">
    <td><input name="Submit" type="submit" value=<?php echo $OrderNumber; ?> ></td>
</form>

Everything works perfectly, except that the $OrderNumber variable shows up on the button itself. I would like the button to display as "Edit", not the $OrderNumber variable that is showing in the attached image.

Buttons with $OrderNumber showing

How could I make the button say "Edit", but apply a posted value of the $OrderNumber value? I have been unable to find a way to accomplish the passing of correct and unique data while also displaying a button that does not confuse the end user.

To get to the next page, I am checking for a posted value at the beginning of the PHP script. If there is a posted value, in this case, $OrderNumber, then the script carries the variables to the next page as shown...

<?php  
    if(!empty ($_POST['Submit']) )
       {
        $_SESSION['OrderID']=$_POST['Submit'];
        header("location:NextPage.php");
        exit;
       }    
?>

But if there is no posted data, the page runs and shows the rows representing the array of database entries. All is well except for this button label.

  • 写回答

4条回答 默认 最新

  • douzhong3887 2017-01-18 10:29
    关注

    Try This

    <form action="ThisPage.php" method="post">
        <input type="hidden" name="order_id" value="<?php echo $OrderNumber; ?>" />
        <td><input name="Submit" type="submit" value="Edit" /> </td>
    </form>
    
    <?php  
        if(!empty ($_POST['Submit']) )
        {
            $_SESSION['OrderID']=$_POST['order_id'];
            header("location:NextPage.php");
            exit;
        }    
    ?>
    

    add hidden field because we can pass any value in form without display we have to add this method.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化