I want to get the value from variable in if else statement here and store the value in $mydata variable.
When I try to print it or use it in another place nothing appear, it look like nothing stored in there and I want to use it in another php block in the same file.
I also tried to make it in function and use it direct in the block I want but the same.
first block that have the value I need to:
<?php
$mydata; //here when I give it a value directly it work so good but I don't need it like that
if($t1) {
//statement
if(//check statement ){
$mydata = 'user1';
}else
// echo message ;
}
else if($t2){
//statement
if(//check statement ){
$mydata = 'user2';
}
} else
// echo message ;
}
?>
Second php block :
if(// check statement ) {
echo ' <form action="file2.php" method="post">
// input fields
<input type="hidden" name="table" value='.$mydata.'>
<input name="login" type="submit" value="submit"> ';
)
My Answer:
php
$mydata = "";
if ($condition) {
$mydata = "Value 1";
} else {
$mydata = "Value 2";
}
You can then use the `$mydata` variable in another PHP block in the same file like this:
php
echo $mydata;
Rate this post
3 of 5 based on 5728 votesComments