Posted: Thu Sep 18, 2008 10:55 pm Post subject: [php/javascript] java var to php then to mysql?
I didn't use search as i don't really know what i am looking for if there is a name for it so...
I was wondering how to get a var (say a number being updated on the same page) then var it to php then insert it into a mysql table as the user leaves the page
I don't really know much about how java works i do know some php/mysql i was thinking something like
Code:
<script language="javascript">
function unload() {
<?php
// update when user leaves page
$javavar = getfunctionnumberiwanttoupdate();
mysql_query("UPDATE atable SET something='$javavar' WHERE id='".$_SESSION['asession']."'");
?>
}
</script>
but i know that doesn't work any help would be nice
Joined: 26 Aug 2007 Posts: 988 Location: Australia
Posted: Fri Sep 19, 2008 12:43 am Post subject:
Java != JavaScript.
And this can be achieved by dynamically creating a form with JavaScript and posting the JavaScript variable to an external PHP page, via Postdata, and using that external PHP page to modify the MySQL table. _________________
Joined: 17 Feb 2008 Posts: 524 Location: Inside the Intel CET shadow stack
Posted: Fri Sep 19, 2008 7:41 am Post subject:
If you don't need any form of obscurity when sending the information, create a PHP script that accepts $_GET parameters and insert a hidden IFRAME element into the calling page. Then navigate the IFRAME to the URL with the parameters you want using javascript.
I haven't used JS for a while, so forgive any errors...
Code:
<iframe id="jsphpframe"></iframe>
[...]
<script type="text/javascript">
<!--
function SendMessageToPHP(param1, param2) {
var f = document.getElementById('jsphpframe');
f.href = "script.php?var1=" + param1 + "&var2=" + param2;
}
-->
</script>
Then in your PHP script use $_GET['var1'] and $_GET['var2'] to read those parameters back out into your script.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum