I am able to display records on same page but i have to display record one page to another page.I have seen many examples but can't quite get it right though.Would you please help me in this? one.php
$ids = $row["ID"];
$username = $row["Name"];
$search_d = array(
'id' => $ids,
'username' => $username,
);
$search_details = http_build_query($search_d);
header('Location: index.php?$search_details=1');
second.php
if(!empty($_GET['$search_details'])):
$name = $_GET['$search_details'];
print_r($name);
echo '<script>
setTimeout(function() {
swal({
title: "details done",
type: "success",
timer: 1500
});
}, 1000);
</script>';
endif;
You didn't concatenate the $search_details
variable in the argument supplied to header
.
$ids = 1;
$username = 'hassan';
$search_d = array(
'id' => $ids,
'username' => $username,
);
$search_details = http_build_query($search_d);
header('Location: index.php?' . $search_details);
on second page you have to do like that .
echo $_GET['id'];
echo $_GET['username'];
you dnt need to get search_details variable . This should work as you expect.
Where to begin...
In one.php:
header('Location: index.php?$search_details=1');
You're using $search_details
within single quotes, meaning the variable will not be used. This will literally be the string index.php?$search_details=1
.
$search_details = http_build_query($search_d);
This will build a query string like ids=value&name=value
. Thus having a =1
after it doesn't make any sense.
In second.php:
If you correct one.php, you should be able to access $_GET['name']
and $_GET['ids']
. $search_details
is again in single quotes which makes little sense and that variable has no context in second.php.
To me, it seems like you have a lot of learning to do still, you should not be on Stackoverflow or building your own code yet, but reading and following guides.