Home Losing PHP Variable value in if statement
Reply: 0

Losing PHP Variable value in if statement

rafal1137
1#
rafal1137 Published in 2017-12-07 13:30:41Z

Recently I am having issue with losing PHP Variable's value in if statement. I have read some of solutions found on StackOverflow and none of them seems to work. POST and GET values are sended properly and are valid. DB is Postgress Am I missing something ?

Here's my script:

$nodeid;
if(isset($_POST['total'])) {
    $ip2 = $_POST['total'];
    echo $ip2;
    $ipaddr = str_replace('::ffff:','', $ip2);
    global $nodeid;
    // Gets Value of id
    $nodeid = $DB->GetOne('SELECT id FROM nodes WHERE ipaddr = ? AND ownerid > 0',
            array(ip2long($ipaddr)));

}
var_dump($nodeid);

if(isset($_GET['download']) && isset($_GET['upload']) && isset($_GET['latency'])) {
//if(isset($_GET['download'], $_GET['upload'], $_GET['latency']))
    $download = preg_replace("/[^0-9]/", "", intval($_GET['download']));
    $upload = preg_replace("/[^0-9]/", "", intval($_GET['upload']));
    $latency = preg_replace("/[^0-9.]/", "", $_GET['latency']);

        $DB->Execute('INSERT INTO speedtests (dt, download, upload, latency, nodeid)
            VALUES (?NOW?, ?, ?, ?, ?)', array($download, $upload, $latency,
            $nodeid)); //<-- $nodeid's value is NULL. 
        die;
}

I checked Postgres log to see what is going on and found

2017-12-07 13:58:58 CET [10571-1] lms@lms ERROR:  null value in column "nodeid" violates not-null constraint
2017-12-07 13:58:58 CET [10571-2] lms@lms DETAIL:  Failing row contains (1512651539, 47, 37, 98.21, null).
2017-12-07 13:58:58 CET [10571-3] lms@lms STATEMENT:  INSERT INTO speedtests (dt, download, upload, latency, nodeid)
                VALUES (EXTRACT(EPOCH FROM CURRENT_TIMESTAMP(0))::integer, '47', '37', '98.21', NULL)

PS: If there are more questions what I am planing to do. I will try to reply fast as I can.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.246627 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO