doudan1123 2016-09-02 18:01
浏览 100

在表单提交后调用当前的id

I have a database where users are allowed to update records via an edit page. After submitting the edits, I'd like the browser to automatically go back to the page they updated to see the results. I thought about using JS to accomplish this:

if(mysqli_query($con, $sql)){
    echo "<script> alert('You have successfully updated.');
            window.location.href='javascript:history.go(-2)';
          </script>";

 }else{
    echo "An error has occurred. Please go back and check the code: ".mysqli_error($con);
 }

but this only forces the browser to go back to the page and not a refreshed page with the changes visible. I need to manually refresh the page to see the results this way.

I also tried:

if(mysqli_query($con, $sql)){
    echo "<script> alert('You have successfully updated.');
            window.location.href='01T.php?id=$id';
          </script>";

 }else{
    echo "An error has occurred. Please go back and check the code: ".mysqli_error($con);
 }

since 01T.php is the page with the displayed info on it, but that didn't work.

How do I redirect the browser to the same id that was edited to see the results, using a more proper PHP solution?

  • 写回答

2条回答 默认 最新

  • doudou32012 2016-09-02 18:12
    关注

    use header to redirect

    if(mysqli_query($con, $sql)){
        header("Location: [url]?id=$id");
    
     }else{
        echo "An error has occurred. Please go back and check the code: ".mysqli_error($con);
     }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)