0

I am having trouble with following code

$res=mysqli_fetch_array($value);
header("location:home.php?result=$res");

This is not working! The url seems to be home.php?result=Array. How can I pass the array $res without using session?

3
  • We can't pass array to url directly. You have to pass value. Show us your code that we can help. Commented Jan 11, 2018 at 7:18
  • 3
    Please refer this Link stackoverflow.com/questions/1763508/… Commented Jan 11, 2018 at 7:20
  • Why you need to pass whole array? Do a SQL query on the target page. Commented Jan 11, 2018 at 7:21

2 Answers 2

2

You should first generate URL-encoded query string using http_build_query:

$res=mysqli_fetch_array($value);
$res = http_build_query($res);
header("location:home.php?result=$res");
Sign up to request clarification or add additional context in comments.

Comments

0

You can prefer http_build_query() function to encode in string and then send to querystring

$res=mysqli_fetch_array($value);
header("location:home.php?result=".http_build_query($res));

Have a look an example for that

 <?php

    $data = array('email' => '[email protected]',
        array("php", "mysql"),
        'age' => 28);
    echo 'page2.php?' . http_build_query($data);
    //output: page2.php?email=test%40test.com&0%5B0%5D=php&0%5B1%5D=mysql&age=28
    ?>

1 Comment

This Solution was already posted by @T.AKROUT.