解决多个变量:添加一些Java的1码读取URL参数,然后修改Ajax代码如下:传递从URL字符串
var d = gup('d');
new Ajax.Request('new_respondent_role_video.php?d=' + d,
感谢大家的帮助。
编辑:
新的URL,用户会点击访问该站点如下:
http://www.xyv.com/ttt/index.php?r=1&d=2010-11-24
此URL包含d
日期变量 - 我需要传递的是通过函数等等它被添加到数据库中。
希望能让你更有意义吗?
H.
嗨,
我希望有可以提供帮助。我在多个页面中继承了下面的代码,并且我被要求对代码进行一些修改,下面详细介绍,但是我真的很挣扎。
为1
URLhttp://www.xyv.com/ttt/index.php?r=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>
本页面引导取决于在URL中为r的登录脚本。
startSurvey代码
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');
}
});
}
打开另一个文件的受访者添加到数据库,然后重新直接用户。
新的答辩文件
<?php
include_once("db.inc.php");
$respondent_id = new_respondent_role_video();
header("Content-type: text/plain");
echo $respondent_id;
?>
返回respondent_id安全地访问该网站可以继续
SQL代码
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);
}
添加新用户,然后返回该用户的ID。
需要什么样的
我需要另一个变量添加到URL,像这样
http://www.xyv.com/ttt/index.php?r=1&d=2010-11-24
然后我需要通过对添加新的用户代码传递变量d
,所以它将日期添加到数据库的日期字段中,如下所示:
$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');");
无论我在哪里花边$GET
代码我无法让页面将此变量传递给Function,因此将d
日期变量添加到数据库中。
任何帮助,想法,建议欢迎。
非常感谢这不是最好的/最简单的,但如果有人可以帮助....非常感激。
荷马。
也许我没看到它,但你能告诉我们用户输入['d'] GET吗? – benhowdle89 2010-11-25 11:54:27
tl; dr但是如果你想修改一个查询字符串,看看`http_build_query()` – 2010-11-25 11:55:40