Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript ajax to php help

    Hi i have some javascript code that passes a varable from javascript to php can someone check my code to see why its not posting to the database, it post to the database but puts 0 instead of the varable.

    javascript with ajax

    Code:
    var xhrobj;
    	var DrawNum;
    function ajax_request() {
      if(navigator.appName == "Microsoft Internet Explorer") {
        xhrobj = new ActiveXObject("Microsoft.XMLHTTP");
      } else {
        xhrobj = new XMLHttpRequest();
      }
      
      xhrobj.open('get', 'ajax.php?DrawNum');
      xhrobj.onreadystatechange = ajax_response;
      xhrobj.send(null);
    }
    
    function ajax_response() {
    	
      if(xhrobj.readyState == 4) {
        document.getElementById('testAjax').innerHTML = xhrobj.responseText;
      }
    }
    function DrawNum2(){
    if(Game_List==0){ //end of list
    Active=0
    document.f1.b1.disabled=false
    document.f1.b3.disabled=true
    return}
    
    rndnum=Math.round(Math.random()*Game_Numbers-1)
    
    Chosen_Number=Game_List.splice(rndnum,1) // remove selected number from Game_List array
    Game_Selectnum[rndnum]=Chosen_Number // create array of selected numbers
    Game_Numbers-- // decrease by 1
    Counter++
    ajax_request();
    document.getElementById("called").innerHTML=Counter
    
    document.getElementById("Selected_Display").innerHTML=Chosen_Number // display selected numbers
    //document.getElementById("List_Remainder").innerHTML=Game_List // use to display unused numbers in list
    
    setTimeout("document.getElementById('num'+Chosen_Number).style.backgroundColor='#66ff66'",100) // delayed highlight of numbers cell
    timer1=setTimeout("DrawNum()",Time)
    //DrawNum()
    Check_Cards(Game_Selectnum[rndnum])
    }
    and here is the php code

    PHP Code:
    @mysql_connect($dbhost,$dbuser,$dbpass);
     @
    mysql_select_db($dbname); 
    include
    "config.php"

    $DrawNum=$_GET['DrawNum']; 
    $DrawNum$_POST['DrawNum'];
     
    $called=1;
    $url=" $sitePath"
    $sql mysql_query("INSERT INTO number (called,  DrawNum,url )          VALUES('$called','$DrawNum','$url' )")        
        or die (
    mysql_error());  echo 'added to the database'


    mysql_close;
    exit; 

  • #2
    New Coder
    Join Date
    Jul 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    replying to myself.
    found the problem
    xhrobj.open('get', 'ajax.php?number=' + Chosen_Number);
    had to put ?number=' + Chosen_Number at the end of ajax.php. 6 hours for that ahhhhhhhhh.


  •  

    Posting Permissions

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