-1

window.open is not working. could you help me solve the problem. i have a table that contains data. id if click on one of it it will redirect to a page where the system counts how many times it have been opened and then it will open a new tab with a specific url. but it is not working . heres my code; please help me. i did not include the $brochure_id and $type in my code below cause i already use it in my code above it would be very long if i include it.

$sql1 = "SELECT * from business_type WHERE business_id = '$type'";
$q1= $conn->query($sql1);
$q1->setFetchMode (PDO::FETCH_ASSOC);

while($r1 = $q1->fetch())
{ 
    if($r1['business_type'] == "Hotel"){
        window.open('search-result-page-hotel.php?id='. $brochure_id . '','_newtab');

    }
    else if($r1['business_type'] == "Restaurant"){
        window.open('search-result-page-restaurant.php?id='. $brochure_id . '','_newtab');
    }
    else if($r1['business_type'] == "Resort"){
        window.open('search-result-page-resort.php?id='. $brochure_id . '','_newtab');
    }
    else if($r1['business_type'] == "Spa"){
        header('Location: search-result-page-spa.php?id='. $brochure_id);
    }
    else if($r1['business_type'] == "Entertainment"){
        window.open('search-result-page-spa.php?id='. $brochure_id . '','_newtab');
    }
}
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • 2
    `window.open` is javascript, not PHP. That should throw an error in your logs. Why not use `header` as you have everywhere else? You also should `exit` after a `header`. – chris85 Jan 07 '17 at 20:38
  • ii change one of them into window open cause the headers are not working. before i uploaded my system in the internet it works well but after i upload i did not work. – Anecito Alima Santillan Jan 07 '17 at 20:51
  • 1
    `window.open` will never work in PHP, is it javascript. Javascript != PHP. Is the question how to open a new tab from PHP? If so see http://stackoverflow.com/questions/12539011/header-location-in-new-tab. Also keep the `JS != PHP` in mind you cant have JS in PHP as JS. Encapsulate it and output it to the browser. – chris85 Jan 07 '17 at 20:53

1 Answers1

1

You need to use the header() function php to set the header response. This will only work at the end of your file

header("Location:  search-result-page-hotel.php?id=". $brochure_id");
Korush Mahdavieh
  • 541
  • 5
  • 15