0

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.

2
  • Maybe i'm not seeing it but can you show us where the user inputs the ['d'] GET? Commented Nov 25, 2010 at 11:54
  • tl;dr but if you want to modify a query string, take a look at http_build_query() Commented Nov 25, 2010 at 11:55

1 Answer 1

2

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'
Sign up to request clarification or add additional context in comments.

2 Comments

Given that the date will be different each time, how do I achieve that?
Thanks wimvds - I added a short piece of code in java to read to the url parameters and passed it to a java variable and sorted - thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.