I still haven't solved my last problem, which codes are

PHP Code:
if (isExistingShowtime($db)) {

    <script language="javascript"> 
        alert("this showtime has been already in my schedule");
        location.replace=("<?php echo $_SERVER['HTTP_REFERER']; ?>");         


I've found that if I gave definitive url to replace something like

it goes to the index page after showing alert.
But I absolutely need $_SERVER['HTTP_REFERER'] as this one is called from various page.
What's wrong with my replace code?