T
thom2002

  • Apr 21, 2007
  • Joined Nov 18, 2006
  • 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

    • 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

      • 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

        • NogDog wrote:

          Well, I guess you could put the whole lot inside a loop, but it's going to be very inefficient and might time out on you if it keeps randomly matching values in the DB. If you care to tell us what it is, functionally, that you are trying to accomplish, I suspect we can come up with a more optimal solution.

          hi NogDog,

          Thanks for looking at this 🙂

          It is a for an online prize draw.

          The winning tickets are generated from a range of random numbers and published.

          Then this is part of the code that generates the entry numbers from the same range of random numbers when a link is clicked on.

          And instantly tells the participant if they have won a prize or not.

          I have it all setup and working, but what is happening is that when a number is drawn it is not excluded from the contest, the same number can be drawn again.

          I have it set so it does not award the prize again but I would like once a number is drawn it cannot be drawn again.

          I hope I explain this clearly 🙂

          Thom

          • hi All,

            I hope someone can help me with this.

            I have been struggling with it and searching for a solution, but I am such a newb that I am probably going about it all wrong.

            If number exists in table pw_reg, generate a new random number and check again. Keep checking until an unused number is found.

            
            else {
            
            $randnumber = rand($rand1,$rand2);
            
            $n_query ="SELECT * FROM pw_reg WHERE pcode='$randnumber'";
            $n_result = mysql_query($n_query);
            
            $numrows = mysql_num_rows($n_result);
            
            if($numrows != 0) {
            
            What do I put in here ?
            
            }
            
            else {
            
            

            Pleeeese

            Thom