SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot doca's Avatar
    Join Date
    Dec 2004
    Location
    Vienna, AT
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    post/get doesn't work?

    Hello

    Can anyone tell me why this doesn't work?
    Code:
    $result = mysql_query("SELECT ip,port FROM radio WHERE id='".$_GET['id']."'");
    This code work
    Code:
    $result = mysql_query("SELECT ip,port FROM radio WHERE id='1'");

    PHP Code:
    <?php
    // Mike Gieson
    // www.wimpyplayer.com
    //  2006 Plaino
    // v1.0

    require_once "db.php";

    $result mysql_query("SELECT ip,port FROM radio WHERE id='".$_GET['id']."'");
        
    $row=mysql_fetch_array($result);
        
    $host=$row['ip'];
        
    $port=$row['port'];

    // Settings
    #$host = "pluto";                // Shoutcast Host
    #$port = "8090";                    // Shoutcast Port
    $mount "/";                    // Used for alternate path to "Streaming URL" -- leave as "/" for the default setup.
    $icecastInterval "100";        // Max number of MB to load
    $wimpySwf "wimpy_button.swf";    // Button SWF file name
    $width "70";                    // Width of the button
    $height "70";                    // Height of the button
    $buttonStyle "circle";        // Button style: Can be "circle" or "square";



    /////////////////////////////////////////////////
    //                                             //
    //     NO NEED TO EDIT ANYTHING BELOW HERE     //
    //                                             //
    //            (unless your a pro)              //
    //                                             //
    /////////////////////////////////////////////////


    $newline "\n";
    $streamURL "http://".$HTTP_SERVER_VARS['HTTP_HOST'].$_SERVER['PHP_SELF'];
    $configs "theFile=".rawurlencode($streamURL."?action=stream")."&icecast=".$icecastInterval."&buttonStyle=".$buttonStyle."&tptBkgd=yes";
    $objectID "wimpybutton";
    $action = @$_REQUEST['action'];


    if(
    $action == "stream"){

        
    // Make socket connection
        
    $errno "errno";
        
    $errstr "errstr";
        
    $fp fsockopen($host$port$errno$errstr30);


        
    // Establish response headers
        
    header("HTTP/1.0 200 OK");
        
    header("Content-Type: audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3");
        
    header("Content-Transfer-Encoding: binary");


        
    // Content-Length is required for Internet Explorer:
        // - Set to a rediculous number
        // = I think the limit is somewhere around 420 MB
        
    header("Content-Length: 100000000");


        
    // Create send headers
        
    $out "GET $mount HTTP/1.1\r\n";
        
    $out .= "Host: $host\r\n";
        
    $out .= "Connection: Close\r\n\r\n";


        
    // Write the returned data back to the resource
        
    fwrite($fp$out);


        
    // Read resource
        
    while (!feof($fp)) {

            
    // Get data in 2048 chuncks
            
    $outData fgets($fp2048);

            
    // Removing shoutcast headers.
            
    if (!stristr($outData"icy") && !stristr($outData"content")){
                echo 
    $outData;
            }

        }

        
    fclose($fp);



    } else if (
    $action == "getJavaScript"){



    $out '// Mike Gieson
    // www.wimpyplayer.com
    //  2006 Plaion Inc.
    // v1.0


    // CONFIGS:

    wimpySwf = "'
    .$wimpySwf.'";
    icecastInterval = "'
    .$icecastInterval.'";
    width = "'
    .$width.'";
    height = "'
    .$height.'";
    configs = "'
    .$configs.'";
    objectID = "'
    .$objectID.'";


    function writeWimpyButton(){
        outputHMTL = "";
        outputHMTL += \'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" \';
        outputHMTL += \'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,47,0" \';
        outputHMTL += \'width="\'+width+\'" \';
        outputHMTL += \'height="\'+height+\'" \';
        outputHMTL += \'id="\'+objectID+\'">\';
        outputHMTL += \'<param name="movie" value="\'+wimpySwf+\'" />\';
        outputHMTL += \'<param name="loop" value="false" />\';
        outputHMTL += \'<param name="menu" value="false" />\';
        outputHMTL += \'<param name="quality" value="high" />\';
        outputHMTL += \'<param name="bgcolor" value="#FFFFFF" />\';
        outputHMTL += \'<param name="flashvars" value="\'+configs+\'" />\';
        outputHMTL += \'<embed src="\'+wimpySwf+\'" \';
        outputHMTL += \'flashvars="\'+configs+\'" \';
        outputHMTL += \'width="\'+width+\'" \';
        outputHMTL += \'height="\'+height+\'" \';
        outputHMTL += \'bgcolor="#FFFFFF" \';
        outputHMTL += \'loop="false" \';
        outputHMTL += \'menu="false" \';
        outputHMTL += \'quality="high" \';
        outputHMTL += \'name="\'+objectID+\'" \';
        outputHMTL += \'align="middle" \';
        outputHMTL += \'allowScriptAccess="sameDomain" \';
        outputHMTL += \'type="application/x-shockwave-flash" \';
        outputHMTL += \'pluginspage="http://www.macromedia.com/go/getflashplayer" />\';
        outputHMTL += \'</object>\';
        document.write(outputHMTL);
        //document.write(\'<br><textarea name="textarea" cols="40" rows="10">\'+outputHMTL+\'</textarea><br>\');
    }'
    ;
    echo 
    "$out";



    } else {

    $out '<HTML>
    <HEAD>
    <TITLE>WimpyCast - Shoutcast through Flash</TITLE>
    <script src="'
    .$streamURL."?action=getJavaScript".'" /></script>
    </HEAD>
    <BODY>
    <P><b>Shoutcast through Flash </b><br>
    Mike Gieson <br>
    <a href="www.wimpyplayer.com">www.wimpyplayer.com</a><br>
     2006 Plaino Inc.<br>
    v1.0 <br></P>

    <SCRIPT LANGUAGE="JavaScript">
    writeWimpyButton();
    </SCRIPT>


    </BODY>
    </HTML>'
    ;


    echo 
    "$out";

    }

    ?>

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Location
    United Kingdom
    Posts
    78
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    When navigating to the page, was there a query string at the end of the URI? It should have looked like this: ?id=1 (where 1 can be any integer).

    You may also want to consider some basic sanitation upon your HTTP GET variable; such as type casting it to an integer:
    PHP Code:

    if(isset($_GET['id'])) {
        
    $id = (int) $_GET['id']; // ensure only integers
    }else{
        
    $id 1// if no query string was entered in the URI, give a default value (optional).
    }

    $result mysql_query("SELECT ip, port FROM radio WHERE id = {$id}"); 

  3. #3
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,129
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Also keep in mind, using $_GET only works if the variable is passed via the URL, it will not work for forms that use POST. If you want to read the variable regardless if it came from the URL or from a form using POST, you may want to try $_REQUEST.

    So taking @modernW ; code, you would have the following:
    PHP Code:
    if(isset($_REQUEST['id'])) {
        
    $id = (int) $_REQUEST['id']; // ensure only integers
    }else{
        
    $id 1// if no query string was entered in the URI, give a default value (optional).
    }

    $result mysql_query("SELECT ip, port FROM radio WHERE id = {$id}"); 

  4. #4
    SitePoint Zealot wh33t's Avatar
    Join Date
    Aug 2011
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by doca View Post
    Hello

    Can anyone tell me why this doesn't work?
    Code:
    $result = mysql_query("SELECT ip,port FROM radio WHERE id='".$_GET['id']."'");
    This code work
    Code:
    $result = mysql_query("SELECT ip,port FROM radio WHERE id='1'");

    PHP Code:
    <?php
    // Mike Gieson
    // www.wimpyplayer.com
    //  2006 Plaino
    // v1.0

    require_once "db.php";

    $result mysql_query("SELECT ip,port FROM radio WHERE id='".$_GET['id']."'");
        
    $row=mysql_fetch_array($result);
        
    $host=$row['ip'];
        
    $port=$row['port'];

    // Settings
    #$host = "pluto";                // Shoutcast Host
    #$port = "8090";                    // Shoutcast Port
    $mount "/";                    // Used for alternate path to "Streaming URL" -- leave as "/" for the default setup.
    $icecastInterval "100";        // Max number of MB to load
    $wimpySwf "wimpy_button.swf";    // Button SWF file name
    $width "70";                    // Width of the button
    $height "70";                    // Height of the button
    $buttonStyle "circle";        // Button style: Can be "circle" or "square";



    /////////////////////////////////////////////////
    //                                             //
    //     NO NEED TO EDIT ANYTHING BELOW HERE     //
    //                                             //
    //            (unless your a pro)              //
    //                                             //
    /////////////////////////////////////////////////


    $newline "\n";
    $streamURL "http://".$HTTP_SERVER_VARS['HTTP_HOST'].$_SERVER['PHP_SELF'];
    $configs "theFile=".rawurlencode($streamURL."?action=stream")."&icecast=".$icecastInterval."&buttonStyle=".$buttonStyle."&tptBkgd=yes";
    $objectID "wimpybutton";
    $action = @$_REQUEST['action'];


    if(
    $action == "stream"){

        
    // Make socket connection
        
    $errno "errno";
        
    $errstr "errstr";
        
    $fp fsockopen($host$port$errno$errstr30);


        
    // Establish response headers
        
    header("HTTP/1.0 200 OK");
        
    header("Content-Type: audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3");
        
    header("Content-Transfer-Encoding: binary");


        
    // Content-Length is required for Internet Explorer:
        // - Set to a rediculous number
        // = I think the limit is somewhere around 420 MB
        
    header("Content-Length: 100000000");


        
    // Create send headers
        
    $out "GET $mount HTTP/1.1\r\n";
        
    $out .= "Host: $host\r\n";
        
    $out .= "Connection: Close\r\n\r\n";


        
    // Write the returned data back to the resource
        
    fwrite($fp$out);


        
    // Read resource
        
    while (!feof($fp)) {

            
    // Get data in 2048 chuncks
            
    $outData fgets($fp2048);

            
    // Removing shoutcast headers.
            
    if (!stristr($outData"icy") && !stristr($outData"content")){
                echo 
    $outData;
            }

        }

        
    fclose($fp);



    } else if (
    $action == "getJavaScript"){



    $out '// Mike Gieson
    // www.wimpyplayer.com
    //  2006 Plaion Inc.
    // v1.0


    // CONFIGS:

    wimpySwf = "'
    .$wimpySwf.'";
    icecastInterval = "'
    .$icecastInterval.'";
    width = "'
    .$width.'";
    height = "'
    .$height.'";
    configs = "'
    .$configs.'";
    objectID = "'
    .$objectID.'";


    function writeWimpyButton(){
        outputHMTL = "";
        outputHMTL += \'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" \';
        outputHMTL += \'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,47,0" \';
        outputHMTL += \'width="\'+width+\'" \';
        outputHMTL += \'height="\'+height+\'" \';
        outputHMTL += \'id="\'+objectID+\'">\';
        outputHMTL += \'<param name="movie" value="\'+wimpySwf+\'" />\';
        outputHMTL += \'<param name="loop" value="false" />\';
        outputHMTL += \'<param name="menu" value="false" />\';
        outputHMTL += \'<param name="quality" value="high" />\';
        outputHMTL += \'<param name="bgcolor" value="#FFFFFF" />\';
        outputHMTL += \'<param name="flashvars" value="\'+configs+\'" />\';
        outputHMTL += \'<embed src="\'+wimpySwf+\'" \';
        outputHMTL += \'flashvars="\'+configs+\'" \';
        outputHMTL += \'width="\'+width+\'" \';
        outputHMTL += \'height="\'+height+\'" \';
        outputHMTL += \'bgcolor="#FFFFFF" \';
        outputHMTL += \'loop="false" \';
        outputHMTL += \'menu="false" \';
        outputHMTL += \'quality="high" \';
        outputHMTL += \'name="\'+objectID+\'" \';
        outputHMTL += \'align="middle" \';
        outputHMTL += \'allowScriptAccess="sameDomain" \';
        outputHMTL += \'type="application/x-shockwave-flash" \';
        outputHMTL += \'pluginspage="http://www.macromedia.com/go/getflashplayer" />\';
        outputHMTL += \'</object>\';
        document.write(outputHMTL);
        //document.write(\'<br><textarea name="textarea" cols="40" rows="10">\'+outputHMTL+\'</textarea><br>\');
    }'
    ;
    echo 
    "$out";



    } else {

    $out '<HTML>
    <HEAD>
    <TITLE>WimpyCast - Shoutcast through Flash</TITLE>
    <script src="'
    .$streamURL."?action=getJavaScript".'" /></script>
    </HEAD>
    <BODY>
    <P><b>Shoutcast through Flash </b><br>
    Mike Gieson <br>
    <a href="www.wimpyplayer.com">www.wimpyplayer.com</a><br>
     2006 Plaino Inc.<br>
    v1.0 <br></P>

    <SCRIPT LANGUAGE="JavaScript">
    writeWimpyButton();
    </SCRIPT>


    </BODY>
    </HTML>'
    ;


    echo 
    "$out";

    }

    ?>

    When you say "doesn't work" what do you mean exactly? do a mysql_error(); exit(); after your mysql_query. That will dump out any error that you are getting. It wouldn't hurt to store your query in a variable called $query either, that way you can echo out what the query actually looks like at runtime.

    like mysql_query($query = 'select * from yatta yatta' . $_GET['id']);

    then you can echo $query, that will let you know if $_GET['id'] is the value you are expecting it to be. You could also take the echo'd out query and dump it into PHPmyadmin or w/e mysql client you use and check in greater detail what's going on.


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
  •