Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
Can you explain what exactly are you trying to do. Maybe we might help you in better way. And do not echo anything other than javascript variable value inside <script> tag – experimentX Feb 20 '11 at 10:46
how is this even kind-of working? – jondavidjohn Feb 20 '11 at 21:40

1 Answer

$matches is a multidimensional array. Try

$script = $match[0][0];
share|improve this answer
No, notify me "undefined offset". – Igor Feb 20 '11 at 17:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.