简体   繁体   English

PHP未定义变量和Javascript

[英]PHP Undefined variable and Javascript

I have tried to figure this out myself I am new to PHP and I know its easy but I am missing something. 我试图自己弄清楚这一点,因为我是PHP的新手,我知道它很简单,但是我缺少一些东西。 I am trying to create something that if someone click a Button have it pass a value called id from the button hyper link for example: 我正在尝试创建一些东西,如果有人单击一个按钮,它会通过按钮超级链接传递一个名为id的值,例如:

     <a href="abc123.html?id=d">Click Here...</a>

Then have the page abc123.html load and at the top of the page run this script below which is to see if id = f then if it does run the javascript code if not don't run it. 然后加载页面abc123.html,并在页面顶部运行以下脚本,该脚本将在下面查看id = f,如果不运行,则是否运行javascript代码。

    <?php
    $vid = $_GET["id"];
    if ($vid != "f") {

       echo "<script type=""text/javascript"">"
            echo "if (screen.width<800)"
            echo "{"
            echo "window.location=""../mobile/default.html"""
            echo "}"
       echo "</script>"
    }
    ?>

However I am getting an PHP Undefined variable error from the Get ID. 但是,我从获取ID中收到一个PHP未定义变量错误。 I have tried to use isset and that doesn't seem to work. 我试图使用isset,这似乎不起作用。 But I know the error is caused if the value of id is blank because the id value might not always be available only if the user clicks on the abc123.html link. 但是我知道如果id的值为空白会导致错误,因为仅当用户单击abc123.html链接时,id值可能并不总是可用。 Can someone please tell me what I am doing wrong? 有人可以告诉我我做错了吗?

I have researched answers here: 我在这里研究了答案:

Undefined variable php 未定义的PHP变量

Undefined variable error in PHP PHP中的未定义变量错误

and here... 和这里...

http://matthom.com/archive/2005/02/19/php-passing-variables-across-pages http://matthom.com/archive/2005/02/19/php-passing-variables-across-pages

and here... 和这里...

http://www.w3schools.com/php/php_if_else.asp http://www.w3schools.com/php/php_if_else.asp

您必须转引号并使用分号结束语句:

echo "<script type=\"text/javascript\">";

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

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