mercredi 16 août 2017

How to use transferred php variable from one file to another in if statement

How to use php variable which is transferred from one file(search.inc.php) into another(anotherpage.php) in if statement?

My connection with MySQL is correct. The problem is following: I can't use variable $bilkon (which is picked up from MySql) in if statement in anotherpage.php.

When echo $bilkon in function display in anotherpage.php, I see answer "Yes", but when I use this $bilkon in if statement I don't get correct answer. I got answer "Bad" from if statement although I got on echo answer "Yes".

search.inc.php

<?php

require 'connect.php'; 

if(isset($_GET['search_text'])){
$search_text = $_GET['search_text'];

if(!empty($search_text)){

    $query="SELECT * FROM kon WHERE sifkon LIKE '%$search_text%'";
    $query_run = mysqli_query($con, $query);

    while($query_row = mysqli_fetch_assoc($query_run)){

    echo $sifkon='<a href="anotherpage.php?
search_text='.$query_row['sifkon'].'">'.$query_row['sifkon'].'  '.'</a>';
       echo $nazkon = $query_row['nazkon'].'<br>';
        $bilkon = $query_row['bilkon'].'<br>';
       $strknj = $query_row['strknj'].'<br>';
       $devknj = $query_row['devknj'].'<br>';
       $orjkon = $query_row['orjkon'].'<br>';
       $tiporj = $query_row['tiporj'].'<br>';

    }

}

}


?>

anotherpage.php

<?php

include 'search.inc.php';


function display(){
global $bilkon;
echo  $bilkon;

if ($bilkon == 'Yes'){
echo 'Good';

}else if($bilkon == 'No'){
echo 'Bad';
}

}
display();




?>

Aucun commentaire:

Enregistrer un commentaire