简体   繁体   English

一页上有两个相同的脚本PHP

[英]Two same script PHP on one page

I have problem with input 2 same php script on one page. 我在一页上输入2个相同的php脚本时遇到问题。

When i put first script everything is alright 当我放第一个脚本时,一切都很好

<div id="jcart">
    <?php $jcart->display_cart();?>
</div>

When I put this same code second time, my all site is crashed and I can't move on to another subpages. 当我第二次输入相同的代码时,我的所有网站都崩溃了,无法继续浏览其他子页面。 I have read that I can use an iframe to get it work, so I have put this code. 我已经读到我可以使用iframe使其正常工作,所以我已经编写了这段代码。

<div id="jcart">
<?php
    if (!isset($_GET['called'])) {
        echo '<iframe src="test.php?called=y"></iframe>';
    }
?> 
</div>

But i have an error 但是我有一个错误

Fatal error: Call to a member function display_cart() on a non-object in /home/movsitev/domains/aba.vxm.pl/public_html/test.php on line 2 致命错误:在第2行的/home/movsitev/domains/aba.vxm.pl/public_html/test.php中的非对象上调用成员函数display_cart()

My test.php look like this 我的test.php看起来像这样

<?php 
    $jcart->display_cart();
?>

You can't call the same id on the same page. 您不能在同一页面上调用相同的ID。 If you want to use multiple elements with the same attribute name, change id="jchart" to class="jchart" . 如果要使用具有相同属性名称的多个元素,请将id="jchart"更改为class="jchart" also do the same in your CSS. 在CSS中也做同样的事情。 Also, make sure you're defining the display_chart function on this page, not on an external one. 另外,请确保在此页面上而不是外部页面上定义display_chart函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM