SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2008
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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 to 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. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,194
    Mentioned
    17 Post(s)
    Tagged
    4 Thread(s)
    AJAX or reload the page and use a flag(get/post) for that operation. You could also go to a separate page where that operation is handled without a flag. However, if you would like to accomplish it without a reload then you must use AJAX.

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2008
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,


    Thank you for your Reply.As you mentioned like that i used Ajax.And write the ajax code.But it is not working.Please help me what's the problem in my code.

    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •