How to use PHP variable on other pages

Asked

Viewed 63 times

0

I have a script that brings the results of an sql search as follows:

$sql = (...);
$result = $db->query($sql);
while ($obj = mysqli_fetch_object($result)) {
    $ids = $obj->id_prestador.",";
}

If I echo $ids after creating the $ids, it brings for example: "710, 720, 730,".

Then on another page I wish I could take this information so I can run a script that sends these ID’s to an application, how can I do?

I tried for cookie that would be the best for me, but then he only brought the first result ("710,").

$sql = (...);
$result = $db->query($sql);
while ($obj = mysqli_fetch_object($result)) {
    $ids = $obj->id_prestador.",";
    setcookie("cookieprestador",$ids)
}

I wish I could pick up on any page the $ids like "710, 720, 730,".

UPDATING: converted into array and used implode and worked, but when I do the setcookie gives Warning message: Cannot Modify header information - headers already sent by output Started at .....

Down as it turned out:

$files = array();
 while ($obj = mysqli_fetch_array($result)) {
  $files[] = $obj["id_prestador"];
 }
$string = implode(', ', $files);
setcookie("cookieprestador",$string);
  • And why don’t you define the cookie after the while?

  • I tried, but then the cookie comes blank

  • @Leandromarzullo fixes error "Cannot Modify header information" by following this https://answall.com/questions/4251/erro-cannot-Modify-header-information if you still have a problem even after fixing the error if you still have another problem edit the question I’ll see if it’s possible to reopen.

1 answer

0

That mistake: Warning: Cannot Modify header information - headers already sent by output Started at

I’ve been through it several times, it happens when you make one output text before storing a cookie or session , if you look at this and if not this...in my case I’ve been through this problem and had no data output before saving the cookie and the solution was to create a new file and paste everything it had in a file in the new one and then solved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.