doushang3352 2017-03-28 12:03
浏览 196

如何保持提交的URL ID?

When I click submit, the data is submitted to the database but the URL id of the book disappears to ----book.php

I want the URL to go back to the id of the page e.g. ----book.php?id=3

Is it possible to keep the first line as action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" and add the value="<?php echo $book_id ?>"?

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
    <input type="hidden" value="<?php echo $book_id ?>" name="book_id" />
    <p>Author: <input type="text" value="<?php echo $_SESSION['author']; ?>" name="author" id="author" readonly /></p>
    <p>Summary: <input type="text" name="summary" value="<?php echo $summary;?>" /></p>
    <p><input type="submit" name="submit" value="Submit" /></p>
    <input type="hidden" name="submitted" value="TRUE" />    
</form>

PHP code:

if (isset($_GET['id'])) {
    $book_id = $_GET['id'];
}
  • 写回答

5条回答 默认 最新

  • dongyin8009 2017-03-28 12:05
    关注

    Please try this code:

    // save values in DB
    
    header('Location: book.php?id=' . $book_id);
    exit;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)