Variable not transferring from one php page to another

Discussion in 'PHP' started by VicarInATutu, Sep 10, 2014.

  1. #1
    Hello,
    I have recently migrated my site to a server with a newer php version of PHP 5.3. Everything seems to be working fine, except that I can no longer send a variable between two php pages through the javascript code that was working before.

    I have a .php file with the following command:

    href='http://www.mysite.com/file.php?FixedIDvalue' class='votepos'

    It sends the numerical value contained in FixedIDvalue to file.php

    file.php GETS this value and sends it to a MySQL database - it works fine.

    However, the class='votepos' statement takes this variable and first processes it through a .js file, before sending it to the aforementioned file.php, enabling the site to run a few commands that hides the clunky redirecting process.

        $(document).ready(function() {
          $(".votepos").click(function(event){
          var vote = $(this).attr('href').replace('http://www.example.com/Music/Update/update22.php?FixedIDvalue=', '');
          $.ajax({
          url: "http://www.vinylsurrender.com/Music/Update/update22.php",
          type: 'post',
          data: {FixedIDvalue:vote},
          success: function(data) {
          window.location.reload(false);
          }
          });
          event.preventDefault();
          });
        });
    Code (markup):


    This javascript was previously sending the FixedIDvalue to file.php, but now it doesn't seem to be doing so, and I don't know why.

    If I remove the class='votepos' from the orignal php statement, or REM out the javascript in the html header then the variable transmits between one php file and the other php file as you would expect, but when it transmits the variable through the .js script, it no longer receives the variable - or at least it doesn't seem to.

    Any ideas?
    Do I need to explain the issue in other words?
    Please let me know,
    Richard.
     
    Last edited: Sep 10, 2014
    VicarInATutu, Sep 10, 2014 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    Maby in the script it's not writen as $_GET['FixedIDvalue'] but as $FixedIDvalue and that doesn't work any more in newer versions of PHP.
    If not, please post more code to look tru..
     
    EricBruggema, Sep 12, 2014 IP
  3. VicarInATutu

    VicarInATutu Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    Thanks for looking at this question. I did find a solution.

    In the jquery .js file, I changed the statement ´type: 'post',´ to ´type: 'get',´. That has resolved the problem of transferring the variable $FixedIDvalue to the .php file.

    If you've got any questions/suggestions/POV, please let me know. I'd be interested in hearing what you think.

    Richard.
     
    VicarInATutu, Sep 14, 2014 IP
  4. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #4
    don't use get! use post where its made for. Change the values in the script from $name to $_POST['name'].
    Way better!
     
    EricBruggema, Sep 16, 2014 IP