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;
        ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?