-3

I am new to php and javascript...

I know js is client side n php is server side

but I want to pass value of variable x to $res

i tried using AJAX but i cant get the result..

Please help..

<SCRIPT LANGUAGE="JavaScript">

...

var x=0;
for (var i = 1; i < po; i++) {
if (Pr[i]['kRs'] == 'pSt') {
x++;
}
...

</SCRIPT>



<?php

$res=

$con = mysql_connect("localhost", "root", "root");
if (!$con) {
   die("Database connection could not be established" . mysql_error());
}

$db_select = mysql_select_db("jaka", $con);
if (!$db_select) {
  die("Database could not be selected" . mysql_error());
}
 $bha=$_uid=$_SESSION['username'];

mysql_query("UPDATE user_info SET extra3='$res' WHERE username='$bha' ");


?>
4

1 回答 1

0

快速而肮脏的例子

your_page.html

_load_jQuery_here_

<SCRIPT LANGUAGE="JavaScript">
...
// your JavaScript code

$.ajax('saving_in_database.php?my_x=' + x);

...
</SCRIPT>

save_in_database.php

<?php

$res = $_GET['my_x'];

// your PHP code 
?>
于 2013-06-05T16:42:26.500 回答