Web Analytics Made Easy -
StatCounter problem with php inside javascript - CodingForum

Announcement

Collapse
No announcement yet.

problem with php inside javascript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem with php inside javascript

    Hi,


    i am using one button.When i click on that button it goes to some javascript function using onclick event.Inside that function i used the some php mysql delete query.In that i am facing one problem. i,e When i open that page that mysql query automatically run without calling the function .

    My requirement is that delete query execute only when click on that button .How can i achieve my requirement.I am trying that from long.But no use.Anybody please help me.Its very urgent.


    Thanks & Regards
    K.Swetha

  • #2
    Hi,

    Could you please post the minimum code from that HTML page + full JS function, so we will be able to test it and see why that function executes by its own (if I correctly understand the question that is the problem).

    Regards

    Comment


    • #3
      Hi,


      Thank you for your Reply.For that i am getting one idea and implemented the ajax concept.But is not working.I am facing the problem when i used this code.Please help me how can we resolve my problem.

      Code:
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <title>Untitled Document</title>
      <script>
      function one(){
      xmlhttp=null;
      url='newpage.php';
      if (window.XMLHttpRequest)
        {// code for all new browsers
        xmlhttp=new XMLHttpRequest();
        }
      else if (window.ActiveXObject)
        {// code for IE5 and IE6
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      if (xmlhttp!=null)
        {
        xmlhttp.onreadystatechange=state_Change;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
        }
      else
        {
        alert("Your browser does not support XMLHTTP.");
        }
      
      }
      
      function state_Change()
      {
      if (xmlhttp.readyState==4)
        {// 4 = "loaded"
        if (xmlhttp.status==200)
          {// 200 = OK
          // ...our code here...
          }
        else
          {
          alert("Problem retrieving XML data");
          }
        }
      }	
      
      </script>
      </head>
      <body>
      <a href="" onclick="one()">Some Example</a>
      </body>
      </html>

      newpage.php

      Code:
      <?
      mysql_query("delete from tbl_ads_productinfo");
      ?>

      When i used that above code in firefox i get the error as

      "Problem retrieving XML data"

      in IE i got the problem as when i click on that hyperlink the page goes working directory folder.Please tell the solution how can i execute my code.

      Comment


      • #4
        As I guessed you where trying to implement ajax... that is good but why you cannot use any ajax class for that? I fully understand that may be you want to know how it works before you will start using somebody’s class but still I will advice you to use for example xAjax.

        It is very easy to use and they already did most of the work You will need max 10 minutes to start using it... so while I will search the problem in your script you could read couple of lines here: http://xajaxproject.org/en/docs-tuto...in-10-minutes/ and I am sure you will like it

        Comment


        • #5
          So here I am. I am 100% sure that you do not have problems with code you have written above. Here is the prove of that:

          Code:
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
          <title>Untitled Document</title>
          <script>
          function one(){
          xmlhttp=null;
          url='newpage.php';
          alert(url);
          }
          
          function state_Change()
          {
          }	
          
          </script>
          </head>
          <body>
          <a href="" onclick="one()">Some Example</a>
          </body>
          </html>
          as you can see the alert is shown only when you click on the link and not on the page's load. That means the request for query will be done only once and when you click on the button.

          So you need to check that this file 'newpage.php' is not included somewhere in the script which executes when that HTML pages is generated. That is the only one logical explanation which came to my mind up to this moment...

          Comment

          Working...
          X