hi All,

I hope someone can help me with this.

Right now I have this which writes the data from the js into the end of a file called score.dat.

javascript extract

strURL = "save.php" + "?s=" + nScore + "&m=" + escape(strMemberName) + "&p=" + nPro + "&t=" + nSeconds + "&c=" + nClicks + "&d=" + escape(strDate);

This is "save.php" file

  $score = fopen("score.dat", "a");

 foreach($HTTP_GET_VARS as $var)

 { 
    fputs($score, "$var" . chr(9)); 
  }
  fputs($score, chr(10)); 
  fclose($score);

What i would like to do is have it insert the data into a mysql database table instead. Using something like

$sql = "INSERT INTO score (score,members_id,pro,seconds,clicks,date) VALUES ('$var1','$var2','$var3','$var4','$var5','$var6';
$result = mysql_query($sql);

But I don't know how to get the variables from the javascript in the correct way.

Thom

    dougal85 wrote:

    You don't know how to get the variables from JavaScript to PHP?

    That's it 🙂

    this gets the variables

    foreach($HTTP_GET_VARS as $var)

    but not, it seems, in any way i can then insert them into a table.

    Is there a way to insert them using a loop?

    Or, is there a way to explode them into distinct variables that I can then insert?

    Or, some other way?

    Thanks

    Thom

      You could use GET method to pass variables. putting variables in the url like this www.domain.com/index.php?var=hello&var2=bye is a demonstration of GET

      allows you access to the variable like this;

      
      echo $_GET['var1'];
      
      echo $_GET['var2'];
      
      

      Is that what you mean?

      If you want to pass variables back and forth between JavaScript you will need to look into using AJAX. Google it 😛

        dougal85 wrote:

        You could use GET method to pass variables. putting variables in the url like this www.domain.com/index.php?var=hello&var2=bye is a demonstration of GET

        allows you access to the variable like this;

        
        echo $_GET['var1'];
        
        echo $_GET['var2'];
        
        

        Is that what you mean?

        If you want to pass variables back and forth between JavaScript you will need to look into using AJAX. Google it 😛

        That is just what I needed 🙂

        Now you have shown me how, it looks so simple that I wonder why I could not see it.

        Thank you, very much appreciated 🙂

        Thom

          15 years later
          Write a Reply...