doulouli8686 2017-07-14 03:11
浏览 47
已采纳

在脚本中调用函数到php

Anyone know how to call goBack() in php?

It keep telling me:

Fatal error: Call to undefined function goBack()

and I don't know why..

Here is my PHP Code:

<?php
include "config.php";
include "session_user.php";
?>
    <script>
        function goBack(){
            alert();
            window.history.go(-1);
        }

    </script>

    <?php
    if(isset($_GET['d'])):

         $stmt = $mysqli->prepare("DELETE FROM bom_equipment WHERE bom_eqp_id=?");
         $stmt->bind_param('s', $id);

         $id = $_GET['d'];

         if($stmt->execute()):
             goBack();
         else:
              echo "<script>alert('".$stmt->error."')</script>";
         endif;
    endif;
    ?>

Any suggestion?

  • 写回答

1条回答 默认 最新

  • douza19870617 2017-07-14 03:29
    关注

    If you want to call javascript function from php. It has lot of ways

    Change your code to follows,

    Method 1

    <?php
    include "config.php";
    include "session_user.php";
    ?>
        <script>
            function goBack(){
                alert();
                window.history.go(-1);
            }
    
        </script>
    
        <?php
        if(isset($_GET['d'])):
    
             $stmt = $mysqli->prepare("DELETE FROM bom_equipment WHERE bom_eqp_id=?");
             $stmt->bind_param('s', $id);
    
             $id = $_GET['d'];
    
             if($stmt->execute()):
               echo "<script>goBack();</script>";
             else:
                  echo "<script>alert('".$stmt->error."')</script>";
             endif;
        endif;
        ?>
    

    Method 2

    <?php
    include "config.php";
    include "session_user.php";
    
        if(isset($_GET['d'])):
    
             $stmt = $mysqli->prepare("DELETE FROM bom_equipment WHERE bom_eqp_id=?");
             $stmt->bind_param('s', $id);
    
             $id = $_GET['d'];
    
             if($stmt->execute()):
                echo "<script>histort.back()</script>";
             else:
                  echo "<script>alert('".$stmt->error."')</script>";
             endif;
        endif;
        ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度