0

Hi,

I'm trying to get the value from a javascript: window.locaiton.href = "db/create_eoi.php?refNum=" + rNum;.

<?php
if(isset($_GET["rNum"])){
        $refNum = trim($_GET["rNum"]);
}
?>

the problem is that where ever I use $refNum I get an error saying Undefined Variable. To be more clear: what im doing is getting a value from a javascript then put that value in a database.

Edited by HuePig

3
Contributors
6
Replies
23
Views
2 Years
Discussion Span
Last Post by HuePig
1

the problem is that variable is in the block.
this is a block

{ start
  your define variable here
} end

so after block you cant see your variable
you need something like this:

    <?php
    $refNum = "";
    if(isset($_GET["rNum"])){
        $refNum = trim($_GET["rNum"]);
    }
    ?>

now your variable will be define and you can use it.

0

setting $refNum before the block - good idea.

window.locaiton.href = "db/create_eoi.php?refNum=" + rNum;

should be (note the typo):

window.location.href = "db/create_eoi.php?refNum=" + rNum;.
0

I'm still having trouble, the code inside the block is not being performed:

<?php
    $refnum = "";
    if(isset($_GET["refNum"])){         
        $refNum = trim($_GET["refNum"]); //assignment not happening
    }
?>

---In Javascript---
window.location.href = "db/create_eoi.php?refNum=" + rNum;

Edited by HuePig

0

check the url querystring and if rNum value is set to anything

Try hard coding:

window.location.href = "db/create_eoi.php?refNum=3";

Edited by diafol

0

Hardcoding doesn't change anything, I also tried using empty($_GET['refNum']) and it is empty.
both java script and php is on a different folders: /root/script/javascript.js and /root/db/create_eoi.php.
I can confirm that the refNum in javascript exists and have a value.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.