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;
        ?>
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题