SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2009
    Location
    Philippines
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript functions need help

    PHP Code:

    <?php
    //function check punkai
    function checkpunkai($kanta)
    {
        
    $song_=ucwords(strtolower($kanta));
        
    $query="SELECT * FROM tbl_music WHERE email='pzknup@yahoo.com' AND title='Punkai - $song_.mp3'";
        
    $result=mysql_query($query);
        while(
    $temp=mysql_fetch_array($result,MYSQL_BOTH))
        {
            
    $tmp=$temp['title'];
        }
        return 
    $tmp;
    }
    //end function check punkai
    ?>

    <script>

    function request_music()
    {
        var _song = document.getElementById('song').value;
        var _a = document.getElementById('a').value;

        if(_song != '' && _a != '' && _song.indexOf("@") <= 0 && _a.indexOf("@") <= 0)
        {
            window.open('request_music.php?song='+_song+'&a='+_a,'_blank', 'height=300, width=330, left=80,top=80');
        }
        else
        {
            alert("Please indicate a song title and artist to submit");
        }
    }

    </script>
    I need help. I have a code above, I want the PHP function checkpunkai($kanta) to be put on the JAVASCRIPT function request_music() how do I apply/implement that?

    Any advices? I'm just a beginner not an expert. I hope I can gain more knowledge.

  2. #2
    SitePoint Addict Zarin Denatrose's Avatar
    Join Date
    Jan 2009
    Location
    Surrey BC, Canada
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you asking how to take the result of your javascript function and pass it to your PHP function, or the other way around?

    PHP->JS
    or
    JS->PHP

  3. #3
    SitePoint Addict Zarin Denatrose's Avatar
    Join Date
    Jan 2009
    Location
    Surrey BC, Canada
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're passing to PHP, you're already half way there.
    You're generating the GET request url as follows:
    request_music.php?song=<Song Name>&a=<Artist>

    In your PHP Code you need to retrieve the variables passed to the $_GET superglobal array.
    PHP Code:
    $song = ($_GET['song']) ? $_GET['song'] : "";
    $artist = ($_GET['a']) ? $_GET['a'] : ""
    Then check if these have the values you need and pass them to the function.
    PHP Code:
    if($song)
    {
        
    checkpunkai($song);



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
  •