解決多個變量:添加一些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