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.

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

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.

Member Avatar

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;.

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;
Member Avatar

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

Try hard coding:

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

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.