0

I only want these update query to work if the event happened. The problem I'm facing is whichever the last query is is overriding the first one and even worse, this update query doesn't even update with the if statement. I've tried to change a lot of things. What am I doing wrong?

    <?php
    $logout_button="header(location:'logout.php')";
    if ($logout_button){
    $logged_out="offline";
    $useronline_sql = mysql_query("UPDATE users SET status = '$logged_out' WHERE username='$username'");
 }?>




<script type="text/javascript">
(function(){
 var moved = false
 window.onmousemove = function(e){
  if(!moved){
      moved = true;
         <?php
         $stat = mysql_query("UPDATE users SET status='online' WHERE email='$email'", $dbh2);
         ?>
  }}})()
  </script>

1 Answer 1

2

When your page is requested, all the PHP code is run, and the HTML and javascript is sent to the browser. So both your SQL queries will be executed and the browser will be sent the following:

<script type="text/javascript">
(function(){
var moved = false
window.onmousemove = function(e){
if(!moved){
     moved = true;

}}})() 
</script>

which won't do anything. You'll probably need to use ajax to send the request to another PHP page that runs your second query.

Sign up to request clarification or add additional context in comments.

Comments

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.