0

I have a form, which is supposed to pass three values via .js to a .php page. First two values are for date range and work fine, but I'm lost on the syntax to pass the third value which is a name.

Then assuming I can get that working, the .php page needs to use that name in an SQL statement and again I'm unsure on the syntax, so assuming the value is "name" I have tried various variations on:-

This is the JS Function, which works ok for the daterange.

    function clickhere()
{
if (checkEmpty("dr_date")) return;
if (checkEmpty("end_date")) return;
if (checkEmpty("name")) return;

var d = convertDate(EL("dr_date").value);
var e = convertDate(EL("end_date").value);
var f = ("name").value;

if (d == null) {
    EL("dr_date").focus();
alert("The date must be in dd/mm/yyyy format.");
return;
}
if (e == null) {
    EL("end_date").focus();
alert("The date must be in dd/mm/yyyy format.");
return;
}

var x = getXmlHttpRequest();
if (x == null) {
    alert("Unable to get XmlHttpRequest");
    return;
}

//syntax problem here?

var u = "outlet-report-dr.php?dr_date=" + d + "&end_date=" + e + "&name=" + f; 

//syntax problem here?

x.open("GET", u, false);
x.send();

var t = x.responseText;
if (t != null && t != "") {
    var e = EL("content");
    e.innerHTML = t;
}

}

Then the PHP, first I get the values:-

    $dateStrt = $_GET['dr_date'];
    $dateFin = $_GET['end_date'];
    $name = $_GET['name'];

Then the SQL statement:-

    $sql = 'SELECT t.*
      FROM transfer t
     WHERE t.name = $name
       AND t.status <> \'cancel\'
     ORDER BY id DESC';

I have all the daterange part working nicely, but not the name, mostly I have just made a mess so far, please assist.

3
  • 1
    What kind of syntax error is it? Does your php get's executed? Also, you're concatenate a string "$name" and you try to get the value of a "name" parameter.. That's not going to happen.. It should be like "&name=BlaBlaBla" Commented Apr 11, 2016 at 0:23
  • 2
    var u = "outlet-report-dr.php?dr_date=" + d + "&end_date=" + e + "$name"; where is $name coming from? Commented Apr 11, 2016 at 0:30
  • I have updated the javascript due to the first comment, hopefully the .js now works. The 'name' comes from the form which also gives the other two variables, which I haven't put up. The date range values need to be altered (works fine), but not the name which just needs to be passed through to the .php. Commented Apr 11, 2016 at 0:32

1 Answer 1

2

your get request should read like this name = value where each variable is separated by a &

eg "outlet-report-dr.php?dr_date=something&end_date=something&name=something

so you will need to change your var u = to read somthing like this

"outlet-report-dr.php?dr_date=" + d + "&end_date=" + e + "&name=" + name where name is the variable that holds your name value.

however if the name value you want is stored in a php varable? try something like this

"outlet-report-dr.php?dr_date=" + d + "&end_date=" + e + "&name=<?php echo $name;?>";

UPDATE

with you SQL... variables are appended to stings using a . in php

eg WHERE t.name = '.$name.'

Sign up to request clarification or add additional context in comments.

Comments

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.