2 Votes Vote

Pass javascript variable to php on javascript generated page

Posted by topdog 458 days ago Questions| javascript php mysql All

I am trying to pass a javascript variable to php, but on the new page I got only "Array". Where did I go wrong?

<script>
new_window.document.write("<title>".concat(x,"</title>","<?PHP
    $rst = mysql_connect("127.0.0.1","root","12345");
    $a =$_SERVER['PHP_SELF'];
    preg_match_all('/<title>(.*?)<\/title>/',$a, $match);

    $script = $match[0];  
    echo $script;

    echo "<br />";

    if (!$rst){
    echo( "<p>Unable to connect to database manager.</p>");
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db("oprema", $rst);

    $result = mysql_query("SELECT * FROM oprema WHERE mreznomesto='$script'");

    while($row = mysql_fetch_array($result)) {
        print( $row['mreznomesto'] . " " . $row['serijskibroj']);
        echo "<br />";
    }

?>"));
</script>

On first page, i've got image map with areas. Onmouseover javascript read area names and send it to javascript generated page. On generated page area name need to be query variable (depending of them show data from database). If i put string instead of variable,everything works fine, result is ok. Only problem is (i think) get variable from html to php on same page.

Originally asked by: Igor on Stack Overflow

Discuss Bury


Who Voted for this Question