Results 1 to 9 of 9

Thread: Blank Variables

  1. #1
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Default Blank Variables

    I have a PHP script that returns a JavaScript. The JavaScript returns correctly, except the PHP-defined variables are...blank.
    here is the PHP:
    PHP Code:
    echo "<script type=\"text/javascript\">var sfonts = " $sfonts "; var ssounds = " $ssounds "; var swallpaper = " $swallpaper "; var sicons = " $sicons "; var ssoundtracks = " $ssoundtracks "; var sprograms = " $sprograms "; var dfonts = " $dfonts "; var dsounds = " $dsounds "; var dwallpaper = " $dwallpaper "; var dicons = " $dicons "; var dsoundtracks = " $dsoundtracks "; var dprograms = " $dprograms "; document.getElementById('textfield').value = sfonts; document.getElementById('textfield2').value = dfonts; document.getElementById('textfield3').value = ssounds; document.getElementById('textfield8').value = dsounds; document.getElementById('textfield4').value = swallpaper; document.getElementById('textfield9').value = dwallpaper; document.getElementById('textfield5').value = sicons; document.getElementById('textfield10').value = dicons; document.getElementById('textfield6').value = ssoundtracks; document.getElementById('textfield11').value = dsoundtracks; document.getElementById('textfield7').value = sprograms; document.getElementById('textfield12').value = dprograms; var sscore = 0; var dscore = 0; if (sfonts > dfonts) { document.getElementById('textfield2').value = ''; sscore = sscore + 1; } if (dfonts > sfonts) { document.getElementById('textfield').value = ''; dscore = dscore + 1; } if (dfonts == sfonts) { sscore = sscore + 1; dscore = dscore + 1; } if (ssounds > dsounds) { document.getElementById('textfield8').value = ''; sscore = sscore + 1; } if (dsounds > ssounds) { document.getElementById('textfield3').value = ''; dscore = dscore + 1; } if (dsounds == ssounds) { sscore = sscore + 1; dscore = dscore + 1; } if (swallpaper > dwallpaper) { document.getElementById('textfield9').value = ''; sscore = sscore + 1; } if (dwallpaper > swallpaper) { document.getElementById('textfield4').value = ''; dscore = dscore + 1; } if (dwallpaper == swallpaper) { sscore = sscore + 1; dscore = dscore + 1; } if (sicons > dicons) { document.getElementById('textfield10').value = ''; sscore = sscore + 1; } if (dicons > sicons) { document.getElementById('textfield5').value = ''; dscore = dscore + 1; } if (dicons == sicons) { sscore = sscore + 1; dscore = dscore + 1; } if (ssoundtracks > dsoundtracks) { document.getElementById('textfield11').value = ''; sscore = sscore + 1; } if (dsoundtracks > ssoundtracks) { document.getElementById('textfield6').value = ''; dscore = dscore + 1; } if (dsoundtracks == ssoundtracks) { sscore = sscore + 1; dscore = dscore + 1; } if (sprograms > dprograms) { document.getElementById('textfield12').value = ''; sscore = sscore + 1; } if (dprograms > sprograms) { document.getElementById('textfield7').value = ''; dscore = dscore + 1; } if (dprograms == sprograms) { sscore = sscore + 1; dscore = dscore + 1; } document.write('UCD ' + sscore + ', ST ' + dscore); if (sscore > dscore) { alert('The Ultimate Customization Discs win!'); } if (dscore > sscore) { alert('SuperTweak wins!'); } if (dscore == sscore) { alert('It\'s a tie!'); }</script>"
    If i go to tally.php?sfonts=85&ssounds=825&swallpaper=45232&sicons=474&ssoundtracks=07&sprograms=777&dfonts=52&dsounds=54&dwallpaper=04&dicons=25&dsoundtracks=0&dprograms= 0, it returns:
    HTML Code:
    <script type="text/javascript">[ICODE]var sfonts = ; var ssounds = ; var swallpaper = ; var sicons = ; var ssoundtracks = ; var sprograms = ; var dfonts = ; var dsounds = ; var dwallpaper = ; var dicons = ; var dsoundtracks = ; var dprograms = ;[/ICODE] document.getElementById('textfield').value = sfonts; document.getElementById('textfield2').value = dfonts; document.getElementById('textfield3').value = ssounds; document.getElementById('textfield8').value = dsounds; document.getElementById('textfield4').value = swallpaper; document.getElementById('textfield9').value = dwallpaper; document.getElementById('textfield5').value = sicons; document.getElementById('textfield10').value = dicons; document.getElementById('textfield6').value = ssoundtracks; document.getElementById('textfield11').value = dsoundtracks; document.getElementById('textfield7').value = sprograms; document.getElementById('textfield12').value = dprograms; var sscore = 0; var dscore = 0; if (sfonts > dfonts) { document.getElementById('textfield2').value = ''; sscore = sscore + 1; } if (dfonts > sfonts) { document.getElementById('textfield').value = ''; dscore = dscore + 1; } if (dfonts == sfonts) { sscore = sscore + 1; dscore = dscore + 1; } if (ssounds > dsounds) { document.getElementById('textfield8').value = ''; sscore = sscore + 1; } if (dsounds > ssounds) { document.getElementById('textfield3').value = ''; dscore = dscore + 1; } if (dsounds == ssounds) { sscore = sscore + 1; dscore = dscore + 1; } if (swallpaper > dwallpaper) { document.getElementById('textfield9').value = ''; sscore = sscore + 1; } if (dwallpaper > swallpaper) { document.getElementById('textfield4').value = ''; dscore = dscore + 1; } if (dwallpaper == swallpaper) { sscore = sscore + 1; dscore = dscore + 1; } if (sicons > dicons) { document.getElementById('textfield10').value = ''; sscore = sscore + 1; } if (dicons > sicons) { document.getElementById('textfield5').value = ''; dscore = dscore + 1; } if (dicons == sicons) { sscore = sscore + 1; dscore = dscore + 1; } if (ssoundtracks > dsoundtracks) { document.getElementById('textfield11').value = ''; sscore = sscore + 1; } if (dsoundtracks > ssoundtracks) { document.getElementById('textfield6').value = ''; dscore = dscore + 1; } if (dsoundtracks == ssoundtracks) { sscore = sscore + 1; dscore = dscore + 1; } if (sprograms > dprograms) { document.getElementById('textfield12').value = ''; sscore = sscore + 1; } if (dprograms > sprograms) { document.getElementById('textfield7').value = ''; dscore = dscore + 1; } if (dprograms == sprograms) { sscore = sscore + 1; dscore = dscore + 1; } document.write('UCD ' + sscore + ', ST ' + dscore); if (sscore > dscore) { alert('The Ultimate Customization Discs win!'); } if (dscore > sscore) { alert('SuperTweak wins!'); } if (dscore == sscore) { alert('It\'s a tie!'); }</script>
    Does anyone have any idea what might be causing this?
    ....(o_ Penguins
    .---/(o_- techno_racing
    +(---//\-' in
    .+(_)--(_)' The McMurdo 500

  2. #2
    Join Date
    Jul 2008
    Posts
    102
    Thanks
    36
    Thanked 6 Times in 6 Posts

    Default

    "except the PHP-defined" - this straightaway leads me to believe that there is a problem with the scope of these variables but I cant see the rest of your code. Make sure that this is being addressed.

    Kind regards
    Dal
    Programmers are tools used to convert Caffeine to code

  3. #3
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

    Default

    Hmm, you're probably thinking that variables defined with GET are automatically turned into global variables. That is not the case, unless register global's in on, which is should not be.

    Just change those variables to get the data from $_GET
    Example:
    PHP Code:
    $_GET['sfonts'

  4. #4
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Default

    That's still not working.
    ....(o_ Penguins
    .---/(o_- techno_racing
    +(---//\-' in
    .+(_)--(_)' The McMurdo 500

  5. #5
    Join Date
    Jul 2008
    Posts
    102
    Thanks
    36
    Thanked 6 Times in 6 Posts

    Default

    Well we could all try guessing some more or you could post some more code because to debug we need more than whats provided;

    where does $sfonts, $ssounds, $swallpaper etc come from? Code please

    Thanks
    Dal
    Programmers are tools used to convert Caffeine to code

  6. #6
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    You might try echoing out the variables at various locations to see what's going on with them. If that doesn't help, you will need to post the rest of the function/code.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  7. #7
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Default

    That is the rest of my code.
    tally.php?sfonts=85&ssounds=825&swallpaper=45232&sicons=474&ssoundtracks=07&sprograms=777&dfonts=52&dsounds=54&dwallpaper=04&dicons=25&dsoundtracks=0&dprograms= 0
    What other code is there?
    EDIT: Does anyone know why it puts a ' ' between '=' and '0' at the end? There's no ' ' in the BBCode.
    ....(o_ Penguins
    .---/(o_- techno_racing
    +(---//\-' in
    .+(_)--(_)' The McMurdo 500

  8. #8
    Join Date
    Jul 2008
    Posts
    102
    Thanks
    36
    Thanked 6 Times in 6 Posts

    Default

    Quote Originally Posted by techno_race View Post
    That is the rest of my code.

    What other code is there?
    EDIT: Does anyone know why it puts a ' ' between '=' and '0' at the end? There's no ' ' in the BBCode.
    If I created a script that pulled in a query string and used it to create javascript then I would expect more code than that. If thats all you have then thats why it doesnt work. I would recommend looking through a tutorial to find out how to use a query string.

    ?somevar=test
    echo $_GET['somevar'];

    will output;
    test

    but
    echo somevar;

    will output;
    (Null)
    Programmers are tools used to convert Caffeine to code

  9. #9
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    Quote Originally Posted by techno_race View Post
    EDIT: Does anyone know why it puts a ' ' between '=' and '0' at the end? There's no ' ' in the BBCode.
    That line is 150 characters, probably the default so that the forum layout isn't too distorted.

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
  •