I want to update my database after a condition in javascript. What I do now is something like:
<a href="#" onclick="hello()">Update me</a>
<srcipt>
function hello(smthing)
{
if(smthing == true)
{
<?php //Update database table ?>
}
}
<script>
I have also tried to update my table according an example in w3schools (http://www.w3schools.com/ajax/ajax_example.asp):
<script>
function hello(smthing)
{
if(smthing==true)
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","db_update.php",true);
xmlhttp.send();
}
}
</script>
In the first case it updates my table even if the variable smthing = false (but if i enter an alert("hi") inside the if, the alert will be displayed only if 'smthing' is true.
In the second case nothing happens. :/
Any help or guidance pls?