duandang6352 2013-01-08 18:51
浏览 91

PHP未定义的变量和Javascript

I have tried to figure this out myself I am new to PHP and I know its easy but I am missing something. 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:

     <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.

    <?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. I have tried to use isset and that doesn't seem to work. 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. Can someone please tell me what I am doing wrong?

I have researched answers here:

Undefined variable php

Undefined variable error in PHP

and here...

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

and here...

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

  • 写回答

1条回答 默认 最新

  • duanduoding2238 2013-01-08 18:54
    关注

    You must escape quotes and finish the statements with a semicolon:

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

报告相同问题?

悬赏问题

  • ¥15 Error in check.length("fill") : 'gpar'成分'fill'的长度不能为零
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导