Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7160519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:24:45+00:00 2026-05-28T13:24:45+00:00

Today I am trying to echo this php mysql statement within my javascript code,

  • 0

Today I am trying to echo this php mysql statement within my javascript code, which commences onclick. However, this php statement seems to run when the page loads on not wait until the onlclick event. Is there any way to solve this? I know that I could use javascript to open other pages and then call back the php statement, but I want this to be light weight.
Thanks!

<script type="text/javascript">
    function exitchatfriend() {
    document.getElementById("clicktoenteraconversation<?php 
                    echo $otherchatuser ?>").style.display='none';
    document.getElementById("chatcontainer").style.display='none';
    <?php mysql_query("DELETE FROM currentconversation 
            WHERE username='$username' and otherchatuser='$otherchatuser'"); ?>
    }
    </script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:24:46+00:00Added an answer on May 28, 2026 at 1:24 pm

    You have a fundamental misunderstanding of the relative roles of PHP and javascript. PHP is a server-side will always execute before the page is sent to the client. This means that the code is never sent to the client, only the results. So if I have:

    <?php echo "1+1 is ".(1+1); ?>
    

    the source code that is sent to the client is

    1+1 is 2
    

    Javascript, on the other hand, is executed on the client’s side. The code is sent to the user’s computer, and you expect (hope) that the user’s browser correctly interprets the code and does what is being asked. (this is why javascript can’t be relied upon for validation, etc, as you can’t control what the client does with the code you send them).

    If you want an onclick event to run a php script, you must use AJAX (which is basically just javascript executing a new page load in the background and doing something with the result). However, ajax is not super fast (you wouldn’t want to run

    for(i=0;i<10000;i++){
       //some ajax call
    }
    

    and you can’t rely on it (so if it’s super important that this query gets run:

    mysql_query("DELETE FROM currentconversation WHERE username='$username' and otherchatuser='$otherchatuser'");
    

    you will want to look for other ways of closing the conversation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to insert data in table in mysql database through php code
Earlier today I tried to do this: Example 1: <?php echo $myVar || rawr;
I got this error today when trying to open a Visual Studio 2008 project
I got an error today while trying to do some formatting to existing code.
i'm trying for days to get this working.. but i still fail. <?php $province
I have this piece of code I'm trying to get to display but no
I have this: <?php echo $this->Form->input('Schedule.0.end_date', array( 'minYear' => date('Y'), 'maxYear' => date('Y')+5 ));
I'm new to Linux and especially to Ubuntu 11 which I'm just trying today
Hi I have been trying this today and haven't had any luck. this stored
I was today trying to figure out on working with WebService and found many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.