doq8211 2014-03-24 11:13
浏览 82
已采纳

通过url传递变量

I'm having a problem I have no idea what's going on, probablly is just a silly thing but I need you help.

If got a very simple login file(starting) is this one:

<?php
  include("conex.phtml");
  $link=Conectarse();
  $username = $_POST['username'];
  $pass =  $_POST['pass'];

  $city = "";
  $latitude = "";
  $longitude = "";
  //$obj = array();
  $empty="empty";
  $rows0="rows0";
  $id="";

  $result=mysql_query("select * from user where username='" . $username . "' and password=" . $pass, $link);
  if(!$result){
    header('Location: http://www.ihaveseen.org/index.html');    
  }else{
    if($rs = mysql_fetch_array($result)){   
      if ($rs==''){
        header('Location: http://www.ihaveseen.org/index.html');   
      } else {
        $id = $rs['id'];
        echo'<script>window.location="http://www.ihaveseen.org/main.php?id=hola";</script>';
        /*header('Location: http://www.ihaveseen.org/main.php?id=hola');*/
        //echo '' . $rs['id'] . '';
        //header('Location: check_incoming.php?id=' . $id); 
      }
    }else{
      header('Location: http://www.ihaveseen.org/index.html');  
    }   
  }

  mysql_close($link);
  exit();
?>

I'm trying to pass via url a variable called id = hola, very simple, right? When I go to the next file, "main.php" the code sends me a syntax error in the javascript script.

<?php 
  $id = $_GET['id'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>Woyou</title>
  </head>
  <link rel="stylesheet" href="./styles/styles16.css" type="text/css" id="css"/>
  <script type="text/javascript" charset="UTF-8">
    var id = getUrlVars()["id"];
    alert("hola");
  </script>
  <body onload="" onunload="GUnload();" onkeydown="" onkeyup="" id="body">
    <div id="guarda" style="display: none;"></div>
    <iframe src='woyou.html' id="woyou_frame" name="woyou_frame" frameborder="0" scrolling="no"></iframe>
  </body>
</html>

What am I doing wrong?

  • 写回答

4条回答 默认 最新

  • duanjianxu4288 2014-03-24 11:18
    关注

    Re-write the html to look like this:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <title>Woyou</title>
        <link rel="stylesheet" href="./styles/styles16.css" type="text/css" id="css"/>
        <script type="text/javascript" charset="UTF-8">
          var id = getUrlVars()["id"];
          alert("hola");
        </script>
      </head>
      <body onload="" onunload="GUnload();" onkeydown="" onkeyup="" id="body">
        <div id="guarda" style="display: none;"></div>
        <iframe src='woyou.html' id="woyou_frame" name="woyou_frame" frameborder="0" scrolling="no"></iframe>
      </body>
    </html>
    

    You had two opening html tags and the script and link tags were not in the head tag like it's supposed to be.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记