How to pull database information in php code

0

Hello, I have a code in PHP, and inside it I would like to pull information.

@$host = "23.98.102.87";
@$port = "9498";

Where's the number s where I wanted to pull the data, I've done the select, but I'd like to know, how could I pull information from the bank inside a php. For example, I have a database, where I already have those ip and number, and I wanted it to come from there, not that I changed manually.

Well, I have an immense code, and it gives errors using echo .

Code:

<?php
$id = $_GET['id'];
$radios1_3 = mysql_query("SELECT * FROM radios ORDER BY id DESC LIMIT 300") or die(mysql_error());
$linha = mysql_fetch_array($radios1_3);
echo "
@$host = " . $linha["sc"] . ";
@$port = " . $linha["sc2"] . ";
@$listenlink = 'http://23.238.135.80:9998/listen.pls';  //make link to stream
@$fp = fsockopen($host, $port); //open connection
if(!$fp) {
@$success=2;  //se-t if no connection
}
if(@$success!=2){ //if connection
@fputs($fp,"GET /index.html HTTP/1.0\r\nUser-Agent: XML Getter (Mozilla Compatible)\r\n\r\n"); //get 7.html
while(!feof($fp)) {
@$pg .= fgets($fp, 1000);
}
@fclose($fp); //close connection
@$paage = ereg_replace(".*<font class=default>Stream Title: </font></td><td><font class=default><b>", "", $pg); //extract data
@$paage = ereg_replace("</b></td></tr><tr><td width=100 nowrap>.*", "", $paage); //extract data
@$pge = ereg_replace(".*<font class=default>Stream Genre: </font></td><td><font class=default><b>", "", $pg); //extract data
@$pge = ereg_replace("</b></td></tr><tr><td width=100 nowrap>.*", "", $pge); //extract data
@$pe = ereg_replace(".*<font class=default>Stream Genre: </font></td><td><font class=default><b>", "", $pg); //extract data
@$pe = ereg_replace("</b></td></tr><tr><td width=100 nowrap>.*", "", $pe); //extract data
@$musica = ereg_replace(".*com:<font class=default>Current Song: </font></td><td><font class=default><b>", "", $pg); //extract data
@$musica = ereg_replace("</b></td></tr></table>.*", "", $musica); //extract data
@$numbers = explode(",",$paage); //extract data
@$servertitle=$numbers[0]; //set variable
@$connected=$numbers[4]; //set variable
}
@$fp2 = fsockopen("$host", $port); //open connection
if(!$fp2) {
@$success2=2;  //se-t if no connection
}
if(@$success2!=2){ //if connection
fputs($fp2,"GET /7.html HTTP/1.0\r\nUser-Agent: XML Getter (Mozilla Compatible)\r\n\r\n"); //get 7.html
while(!feof($fp2)) {
@$pg2 .= fgets($fp2, 1000);
}
fclose($fp2); //close connection
@$pag = ereg_replace(".*<body>", "", $pg2); //extract data
@$pag = ereg_replace("</body>.*", ",", $pag); //extract data
@$numbers = explode(",",$pag); //extract data
$currentlisteners=$numbers[0]; //set variable
}
// ATUALIZADOR
if(@$_GET['ver'] == "dj"){
echo"$paage";
}
if(@$_GET['ver'] == "ouvintes"){
echo $currentlisteners;
}
if(@$_GET['ver'] == "musica"){
echo "$musica";
}
if(@$_GET['ver'] == "programa"){
echo"$pge";
}
if(@$_GET['ver'] == "imgloc"){
echo'<div id="boneco" style="background:url(https://www.habbo.com.br/habbo-imaging/avatarimage?img_format=gif&user='.$paage.'&action=std&direction=2&head_direction=2&gesture=spk&size=b);"></div>';
}
";
// ATUALIZADOR
?>
    
asked by anonymous 26.06.2015 / 23:56

2 answers

1

The modifications I suggest are, remove the echo and its closing

$linha = mysql_fetch_array($radios1_3);
echo "

//Muito código depois...

if(@$_GET['ver'] == "imgloc"){
echo'<div id="boneco" style="background:url(https://www.habbo.com.br/habbo-imaging/avatarimage?img_format=gif&user='.$paage.'&action=std&direction=2&head_direction=2&gesture=spk&size=b);"></div>';
}
"; //<---- Fim do echo 

Remove all% with% because they hide the errors / warning they must be treated, sometimes only @ already solve.

If you only get the first record, you can leave the limit at 1 instead of 300

$radios1_3 = mysql_query("SELECT * FROM radios ORDER BY id DESC LIMIT 300") or die(mysql_error());
$linha = mysql_fetch_array($radios1_3);

All changes:     

    $id = $_GET['id'];
    $radios1_3 = mysql_query("SELECT * FROM radios ORDER BY id DESC LIMIT 1") or die(mysql_error());
    $linha = mysql_fetch_array($radios1_3);
    $host =  $linha["sc"];
    $port =  $linha["sc2"];
    $listenlink = 'http://23.238.135.80:9998/listen.pls';  //make link to stream
    $fp = fsockopen($host, $port); //open connection
    if(!$fp) {
        $success=2;  //se-t if no connection
    }

    if($success!=2){ //if connection
        fputs($fp,"GET /index.html HTTP/1.0\r\nUser-Agent: XML Getter (Mozilla Compatible)\r\n\r\n"); //get 7.html
        while(!feof($fp)) {
            $pg .= fgets($fp, 1000);
        }
        fclose($fp); //close connection
        $paage = ereg_replace(".*<font class=default>Stream Title: </font></td><td><font class=default><b>", "", $pg);
        $paage = ereg_replace("</b></td></tr><tr><td width=100 nowrap>.*", "", $paage);
        $pge = ereg_replace(".*<font class=default>Stream Genre: </font></td><td><font class=default><b>", "", $pg);
        $pge = ereg_replace("</b></td></tr><tr><td width=100 nowrap>.*", "", $pge);
        $pe = ereg_replace(".*<font class=default>Stream Genre: </font></td><td><font class=default><b>", "", $pg);
        $pe = ereg_replace("</b></td></tr><tr><td width=100 nowrap>.*", "", $pe);
        $musica = ereg_replace(".*com:<font class=default>Current Song: </font></td><td><font class=default><b>", "", $pg);
        $musica = ereg_replace("</b></td></tr></table>.*", "", $musica);
        $numbers = explode(",",$paage); //extract data
        $servertitle=$numbers[0]; //set variable
        $connected=$numbers[4]; //set variable
    }

    $fp2 = fsockopen("$host", $port); //open connection
    if(!$fp2) {
        $success2=2;  //se-t if no connection
    }

    if($success2!=2){ //if connection
        fputs($fp2,"GET /7.html HTTP/1.0\r\nUser-Agent: XML Getter (Mozilla Compatible)\r\n\r\n"); //get 7.html
        while(!feof($fp2)) {
            $pg2 .= fgets($fp2, 1000);
        }
        fclose($fp2); //close connection
        $pag = ereg_replace(".*<body>", "", $pg2);
        $pag = ereg_replace("</body>.*", ",", $pag);
        $numbers = explode(",",$pag);
        $currentlisteners=$numbers[0];
    }
    // ATUALIZADOR
    if(isset($_GET['ver'])){
        if($_GET['ver'] == "dj"){
            echo $paage;
        }

        if($_GET['ver'] == "ouvintes"){
            echo $currentlisteners;
        }

        if($_GET['ver'] == "musica"){
            echo $musica;
        }

        if($_GET['ver'] == "programa"){
            echo $pge;
        }

        if($_GET['ver'] == "imgloc"){
            echo'<div id="boneco" style="background:url(https://www.habbo.com.br/habbo-imaging/avatarimage?img_format=gif&user='.$paage.'&action=std&direction=2&head_direction=2&gesture=spk&size=b);"></div>';
        }
    }   
    // ATUALIZADOR
    ?>
    
27.06.2015 / 01:06
0

If you already have select, just do the following:

$linha = mysql_fetch_array($seu_select);
echo "@$host = " . $linha["ip"] . "; @$port = " . $linha["porta"];

Assuming you are using mysql_query, not PDO or MySQLi, if you are using one of the two, tell me.

    
27.06.2015 / 00:04