1

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.

2
  • 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 Commented Feb 20, 2011 at 10:46
  • how is this even kind-of working? Commented Feb 20, 2011 at 21:40

1 Answer 1

0

$matches is a multidimensional array. Try

$script = $match[0][0];
1
  • No, notify me "undefined offset". Commented Feb 20, 2011 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.