dphw5101 2010-11-25 11:50
浏览 105
已采纳

从URL字符串传递多个变量

SOLVED: added some java to the Page 1 code to read the URL parameters and then modified the Ajax code as follows:

var d = gup( 'd' );

    new Ajax.Request('new_respondent_role_video.php?d=' + d,

Thanks to you all for your help.

EDIT:

The new url that a user will click to access the site is as follows:

http://www.xyv.com/ttt/index.php?r=1&d=2010-11-24

This URL contains the d date variable - I need to pass that through the Function so it gets added to the database.

Hope that makes a little more sense?

H.

Hi,

I hope some can help. I have inherited the following code across multiple pages and I have been asked to make some modifications to the code, detailed below but am really struggling.

URL for Page 1

http://www.xyv.com/ttt/index.php?r=1

Page 1

<?php include_once("db.inc.php");
//$i = 2;
$i = $_GET['r'];
if ($i == 1) {
  include("_inc/login_script_role_video.php");
  echo "<h1>Loading questionnaire please wait.</h1>";
}else if($i == 2){
  include("_inc/login_scriptm_role_video.php");
  echo "<h1>Loading questionnaire please wait.</h1>";
}else if($i == 3){
  include("_inc/login_scriptd_role_video.php");
  echo "<h1>Loading questionnaire please wait.</h1>";
}else{
  echo "<h1>You have tried to access the survey without a correct id, ",
       "please refer to your invitation email.</h1>";
}

//echo $i;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title><?php include("_inc/title.php"); ?></title>
  <link rel="stylesheet" type="text/css" href="main.css" />
  <script src="main.js" type="text/javascript"></script>
  <script src="javascripts/scriptaculous.shrunk.js" 
  type="text/javascript" charset="ISO-8859-1"></script>
</head>
<body onload="startSurvey();">

</body>
</html>

This page directs to a login script depending on the r in the URL.

startSurvey code

function startSurvey(){
/* var respondent_id = document.getElementById('respondent_id').value;
if(1==0) { if open survey, use respondent_id.length==0*/
    new Ajax.Request('new_respondent_role_video.php',
      {
        method:'get',
        onSuccess: function(transport){
          var respondent_id = transport.responseText;
          window.location='prog-role-video.php?r=' + respondent_id;
        },
        onFailure: function(){
              Effect.Appear('problem');
            }
      });
}

Opens another file to add a respondent to the database and then re-direct the user.

New respondent file

<?php
include_once("db.inc.php");

$respondent_id = new_respondent_role_video();

header("Content-type: text/plain");

echo $respondent_id;
?>

Returns the respondent_id to secure access to the site can continue

SQL code

function new_respondent_role_video() {
$d = $_GET['d'];

global $link;
$proc = mysqli_prepare($link, "INSERT INTO trespondent ".
      "(code, link, role, course, page, dates) ".
      "VALUES (uuid(), 'http://www.1.xyc.co.uk/tmg/prog-role-video.php?r=', ".
      "'STAFF', 'story telling', '8', '2010-10-10');");
mysqli_stmt_execute($proc);
$id = mysqli_insert_id($link);
mysqli_stmt_fetch($proc);
mysqli_stmt_close($proc);
mysqli_clean_connection($link);

global $link;
$proc = mysqli_prepare($link, "SELECT code FROM trespondent ".
    "WHERE respondent_id = ?");
mysqli_stmt_bind_param($proc, "i", $id);    
mysqli_stmt_execute($proc);
mysqli_stmt_bind_result($proc, $code);
mysqli_stmt_fetch($proc);
mysqli_stmt_close($proc);
mysqli_clean_connection($link);
return($code);

}

Adds new user and then returns the ID for that user.

What is needed

I need to add another variable to the url, like so

http://www.xyv.com/ttt/index.php?r=1&d=2010-11-24

I then need to pass that variable d through to the add new user code, so it adds the dates into the dates field of the database, something like this:

$d = $_GET['d'];

$proc = mysqli_prepare($link, "INSERT INTO trespondent_tmg ".
  "(code, link, role, course, page, dates) VALUES (uuid(), ".
  "'http://www.1.xyz.co.uk/xyz/prog-role-video.php?r=', ".
  "'STAFF', 'The role of video in multi-media story telling', '8', '$d');");

No matter where I place the $GET code I cannot get the pages to pass this variable to Function and thus add the d date variable to the database.

Any help, ideas, suggestions welcomed.

Fully appreciate this is not the best/easiest but if someone can help....very much appreciated.

Homer.

  • 写回答

1条回答 默认 最新

  • douban5644 2010-11-25 12:01
    关注

    You probably just have to alter the following line to include your d variable (unless there are some other things you didn't mention) :

    new Ajax.Request('new_respondent_role_video.php'
    

    ie.

    new Ajax.Request('new_respondent_role_video.php?d=2010-11-25'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂