应该从footer.php调用函数返回undefined

时间:2013-03-31 00:04:10

标签: php javascript

我正在研究一个在线报价系统(从头开始),由于我的PHP页脚中的内容,我得到一个例外。

当用户单击“提交”时,只有在对SQL数据库的调用块被注释掉时,才会调用MMJS / MPJS / DPJS文档中的函数(接近下面代码的末尾)。否则,我得到一个例外,说这些文档中的函数是未定义的。

为什么此代码块会导致稍后调用的文档中的函数无法访问?

代码:

        <div id="results"></div>

        </div><!-- #wrapper -->

        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="<?PHP echo $relpath; ?>js/vendor/jquery-1.9.0.min.js"><\/script>')</script>
        <script src="<?PHP echo $relpath; ?>js/plugins.js"></script>
        <script src="<?PHP echo $relpath; ?>js/main.js"></script>

        // <script type="text/javascript">
            // <?PHP
                // $stmt = $mysqli->prepare("SELECT * FROM `Fixed Quoter Prices` WHERE 1");
                // $stmt->bind_result($db_DPbaseRate, $db_MPbaseRate, $db_MMbaseRate, $db_raidRate, $db_boxRate, $db_metaRate, $db_sanRate,$db_hbaRate, $db_twoTB, $db_threeTB, $db_fourTB, $db_switchUpgrade, $db_tenRate, $db_taxRate);
                // $stmt->execute();
                // $stmt->fetch();

                // echo "var DPbaseRate = $db_DPbaseRate;";
                // echo "var MPbaseRate = $db_MPbaseRate;";
                // echo "var MMbaseRate = $db_MMbaseRate;";
                // echo "var raidRate = $db_raidRate;";
                // echo "var boxRate = $db_boxRate;";
                // echo "var metaRate = $db_metaRate;";
                // echo "var sanRate = $db_sanRate;";
                // echo "var hbaRate = $db_hbaRate;";
                // echo "var twoTB = $db_twoTB;";
                // echo "var threeTB = $db_threeTB;";
                // echo "var fourTB = $db_fourTB;";
                // echo "var switchUpgrade = $db_switchUpgrade;";
                // echo "var tenRate = $db_tenRate;";
                // echo "var taxRate = $db_taxRate;";
            // ?>

        // </script>

        <?PHP if($title == 'Media Master') : ?>
        <script type="text/javascript" src="../js/MMJS.js"></script>
        <?PHP elseif($title == 'Media Pro') : ?>
        <script type="text/javascript" src="../js/MPJS.js"></script>
        <?PHP elseif($title == 'Desk Pro') : ?>
        <script type="text/javascript" src="../js/DPJS.js"></script>
        <?PHP endif; ?>

    </body>
</html>

1 个答案:

答案 0 :(得分:0)

想出来!我忘记了我最初的SQL数据库连接。

使用blockquote中添加的行修正了内部脚本:

<script type="text/javascript">
            <?PHP
  

$ mysqli = new mysqli('12 .34.56.78','someuser','somepass','foo');

                $stmt = $mysqli->prepare("SELECT * FROM `Fixed Quoter Prices` WHERE 1");
                $stmt->bind_result($db_DPbaseRate, $db_MPbaseRate, $db_MMbaseRate, $db_raidRate, $db_boxRate, $db_metaRate, $db_sanRate,$db_hbaRate, $db_twoTB, $db_threeTB, $db_fourTB, $db_switchUpgrade, $db_tenRate, $db_taxRate);
                $stmt->execute();
                $stmt->fetch();

                echo "var DPbaseRate = $db_DPbaseRate;";
                echo "var MPbaseRate = $db_MPbaseRate;";
                echo "var MMbaseRate = $db_MMbaseRate;";
                echo "var raidRate = $db_raidRate;";
                echo "var boxRate = $db_boxRate;";
                echo "var metaRate = $db_metaRate;";
                echo "var sanRate = $db_sanRate;";
                echo "var hbaRate = $db_hbaRate;";
                echo "var twoTB = $db_twoTB;";
                echo "var threeTB = $db_threeTB;";
                echo "var fourTB = $db_fourTB;";
                echo "var switchUpgrade = $db_switchUpgrade;";
                echo "var tenRate = $db_tenRate;";
                echo "var taxRate = $db_taxRate;";
            ?>
        </script>