Help - Search - Members - Calendar
Full Version: New Type of shoutcast script. Not working...
Weborum Webmaster Forum > Web Page Design > PHP
Crab-Apple
Well I got this new script off hotscripts for showing shoutcast information Like current dj, Current song, ect... here is the file http://www.krinj.net/misc/download.php?fil...tatusv1.7.3.zip and I followed the readme file and every time i try to use the installation file it says

CODE
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/virtual/site200/fst/var/www/html/radio/stats/dbconnect.php on line 20

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/virtual/site200/fst/var/www/html/radio/stats/djdetect.php on line 20
Sorry but the tables could not be created, please try again. \




I know what to put in the db, user, host, pass, ect... I have everything correct but it seems there is something wrong with these codes.




dbconnect:


CODE
<?php
//////////////////////////////////////////////////////////////////////////////
// DJ Status v1.7.3               //
// ©2004 Nathan Bolender www.2004design.tk         //
// Free to use on any website            //
//////////////////////////////////////////////////////////////////////////////

if (file_exists($filename))  {
echo "<strong>Please delete the 'install' folder, or if you haven't installed the script yet, please do that <a href=\"install\">now</a>. Thank you.</strong>";
} else {
if(!$db = @mysql_connect("$dbhost", "$dbuser", "$dbpass"))
die('<font size=+1>An Error Occurred</font><hr>Unable to connect to the database. <BR>Check $dbhost, $dbuser, and $dbpass in config.php.');

if(!@mysql_select_db("$dbname",$db))
die("<font size=+1>An Error Occurred</font><hr>Unable to find the database <b>$dbname</b> on your MySQL server.");


$query="SELECT * FROM currentdj_settings WHERE id = '1'";
$result=mysql_query($query);
while($row = mysql_fetch_array($result)) {
  $mode = "$row[setting]";
}

if ($mode == 0) {
include ("djdetect.php");
} else {

if (isset($dj)) {
$dj = NULL;
}

$query="SELECT * FROM currentdj WHERE active = '1'";
$result=mysql_query($query);
while($row = mysql_fetch_array($result)) {
  $dj = "$row[dj]";
}
}

////////////////////////////////////////////////////////////////////////////
if (isset($dj)) {


if(!$db = @mysql_connect("$dbhost", "$dbuser", "$dbpass"))
die('<font size=+1>An Error Occurred</font><hr>Unable to connect to the database. <BR>Check $dbhost, $dbuser, and $dbpass in config.php.');

if(!@mysql_select_db("$dbname",$db))
die("<font size=+1>An Error Occurred</font><hr>Unable to find the database <b>$dbname</b> on your MySQL server.");

$query="SELECT * FROM currentdj WHERE dj = '$dj'";
$result=mysql_query($query);
while($row = mysql_fetch_array($result)) {
  $name = "$row[name]";
  $address = "$row[address]";
  $aim = "$row[aim]";
  $msn = "$row[msn]";
  $yim = "$row[yim]";
  $icq = "$row[icq]";
}


}
}
?>






and

djdetect:
CODE
<?php
//////////////////////////////////////////////////////////////////////////////
// DJ Status v1.7.3               //
// ©2004 Nathan Bolender www.2004design.tk         //
// Free to use on any website            //
//////////////////////////////////////////////////////////////////////////////

if(!$db = @mysql_connect("$dbhost", "$dbuser", "$dbpass"))
die('<font size=+1>An Error Occurred</font><hr>Unable to connect to the database. <BR>Check $dbhost, $dbuser, and $dbpass in config.php.');

if(!@mysql_select_db("$dbname",$db))
die("<font size=+1>An Error Occurred</font><hr>Unable to find the database <b>$dbname</b> on your MySQL server.");

if (isset($dj)) {
$dj = NULL;
}

$query="SELECT * FROM currentdj";
$result=mysql_query($query);
while($row = mysql_fetch_array($result)) {
      $did = "$row[dj]";
      $aliasa = "$row[alias1]";
$aliasb = "$row[alias2]";
$aliasc = "$row[alias3]";
if (isset($aliasa)) {
   if (stristr($servertitle, $aliasa) !== FALSE) {
$dj = $did;
}
}
if (isset($aliasb)) {
if (stristr($servertitle, $aliasb) !== FALSE) {
$dj = $did;
}
}
if (isset($aliasc)) {
if (stristr($servertitle, $aliasc) !== FALSE) {
$dj = $did;
}
}
  }
?>




also here is the config file:

CODE
<?php
//////////////////////////////////////////////////////////////////////////////
// DJ Status v1.7.3               //
// ©2004 Nathan Bolender www.2004design.tk         //
// Free to use on any website            //
//////////////////////////////////////////////////////////////////////////////
// Configuration
// Add your information in the quotes on each line

# Database
$dbhost = "localhost";  // MySQL Server, Usually localhost
$dbname = "";   // MySQL database name
$dbuser = "";   // MySQL username
$dbpass = "";   // MySQL password

# Shoutcast
$scdef = "";   // Default station name to display when server or stream is down (ex: SNRadio)
$scip = "";   // ip or url of shoutcast server - no http:// (ex: radio.radiosite.com)
$scport = "";   // port of shoutcast server (ex: 8000)
$scpass = ">";   // password to shoutcast server

# Admin Panel
$adminname = "";    // Name to display when in manual mode
$adminpass = ""; // Password for the administration panel

// End configuration
////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// Do not edit below this line //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////

$version = "1.7.3";

$filename = "admin/install/index.php";

// Shoutcast Server Stats
$scfp = @fsockopen("$scip", $scport, &$errno, &$errstr, 10);
if(!$scfp) {
$scsuccs=1;
# echo'<strong>'.$scdef.' is Offline</strong><br>';
}
if($scsuccs!=1){
fputs($scfp,"GET /admin.cgi?pass=$scpass&mode=viewxml HTTP/1.0\r\nUser-Agent: SHOUTcast Song Status (Mozilla Compatible)\r\n\r\n");
while(!feof($scfp)) {
$page .= fgets($scfp, 1000);
}
//define  xml elements
$loop = array("STREAMSTATUS", "BITRATE", "SERVERTITLE", "CURRENTLISTENERS");
$y=0;
while($loop[$y]!=''){
$pageed = ereg_replace(".*<$loop[$y]>", "", $page);
$scphp = strtolower($loop[$y]);
$$scphp = ereg_replace("</$loop[$y]>.*", "", $pageed);
if($loop[$y]==SERVERGENRE || $loop[$y]==SERVERTITLE || $loop[$y]==SONGTITLE || $loop[$y]==SERVERTITLE)
 $$scphp = urldecode($$scphp);

// uncomment the next line to see all variables
//echo'$'.$scphp.' = '.$$scphp.'<br>';
$y++;
}
//end intro xml elements

//get song info and history
$pageed = ereg_replace(".*<SONGHISTORY>", "", $page);
$pageed = ereg_replace("<SONGHISTORY>.*", "", $pageed);
$songatime = explode("<SONG>", $pageed);
$r=1;
while($songatime[$r]!=""){
$t=$r-1;
$playedat[$t] = ereg_replace(".*<PLAYEDAT>", "", $songatime[$r]);
$playedat[$t] = ereg_replace("</PLAYEDAT>.*", "", $playedat[$t]);
$song[$t] = ereg_replace(".*<TITLE>", "", $songatime[$r]);
$song[$t] = ereg_replace("</TITLE>.*", "", $song[$t]);
$song[$t] = urldecode($song[$t]);
$dj[$t] = ereg_replace(".*<SERVERTITLE>", "", $page);
$dj[$t] = ereg_replace("</SERVERTITLE>.*", "", $pageed);
$r++;
}
//end song info

fclose($scfp);
}

if (file_exists($filename))  {
$nodb == "1";
}

if (isset($nodb) == FALSE) {
include ("dbconnect.php");
}

?>



also again here is the index.php file located in admin/install/ this creates the tables.


CODE
<?php
//////////////////////////////////////////////////////////////////////////////
// DJ Status v1.7.3               //
// ©2004 Nathan Bolender www.2004design.tk         //
// Free to use on any website            //
//////////////////////////////////////////////////////////////////////////////

include ("../header.inc");
include ("../../config.php");

if(!$db = @mysql_connect("$dbhost", "$dbuser", "$dbpass"))
die('<font size=+1>An Error Occurred</font><hr>Unable to connect to the database. <BR>Check $dbhost, $dbuser, and $dbpass in config.php.');
if(!@mysql_select_db("$dbname",$db))
die("<font size=+1>An Error Occurred</font><hr>Unable to find the database <b>$dbname</b> on your MySQL server.");

$result1 = mysql_query("CREATE TABLE `currentdj` (
`dj` int(11) NOT NULL auto_increment,
`active` int(11) NOT NULL default '0',
`name` text NOT NULL,
`password` text NOT NULL,
`address` text NOT NULL,
`aim` text NOT NULL,
`msn` text NOT NULL,
`yim` text NOT NULL,
`icq` text NOT NULL,
`alias1` text NOT NULL,
`alias2` text NOT NULL,
`alias3` text NOT NULL,
PRIMARY KEY  (`dj`)
) TYPE=MyISAM AUTO_INCREMENT=1; ");

$result2 = mysql_query("CREATE TABLE `currentdj_settings` (
`id` int(11) NOT NULL auto_increment,
`name` text NOT NULL,
`setting` text NOT NULL,
PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1; ");

$result3 = mysql_query("INSERT INTO `currentdj_settings` VALUES (1, 'Mode', '0'); ");



if (($result1 == TRUE) && ($result2 == TRUE) && ($result3 == TRUE)) {

echo "Congratulations! The script was successfully installed!<br><b>Make sure you delete the admin/install folder before continuing to use the script.</b><br>Please click continue to enter the administration panel and add your DJs. <br><a href=\"../index.php\">Continue...</a>";

} else {

echo "Sorry but the tables could not be created, please try again.";
}
include ("../footer.inc");
?>


Can anyone help?
Timo
Did you try running the index.php for the admin script? (Stupid question, I know but I can't see anything wrong with a clear look...)

Also, could you do this...
in the two files that errors are appearing in

change
$result=mysql_query($query);
to
$result=mysql_query($query) or die(mysql_error());

That'll tell us what's going wrong. Thanks. smile.gif
Timo
I'm going to move this to the PHP forum because this isn't really related to tutorials and it's not one of the scripts here.
smile.gif May get extra responses there too.
Josh
Sounds to me like you haven't set up your database up correctly.
Crab-Apple
Really. Ok I'll try what he said and change the variables



Edited:

Ok what he said to do worked but not i got another error...


Table 'habbomedia_ca_-_currentdj.currentdj_settings' doesn't exist
Josh
That table doesn't exist.
morrowasted
I have one in my signature, see tongue.gif. Heres the code, you can just edit it around.

CODE

<?php

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
Header("Content-type: image/png");

// Fill in your own server information here:
$host = "IP";
$port = "PORT";
$listenlink = 'LINK';  //make link to stream

$fp = fsockopen("$host", $port, &$errno, &$errstr, 30); //open connection
if(!$fp) {
 $success=2;  //se-t if no connection
}
if($success!=2){ //if connection
 fputs($fp,"GET /7.html HTTP/1.0\r\nUser-Agent: XML Getter (Mozilla Compatible)\r\n\r\n"); //get 7.html
 while(!feof($fp)) {
  $page .= fgets($fp, 1000);
 }
 fclose($fp); //close connection
 $page = ereg_replace(".*<body>", "", $page); //extract data
 $page = ereg_replace("</body>.*", ",", $page); //extract data
 $numbers = explode(",",$page); //extract data
 $currentlisteners=$numbers[0]; //set variable
 $connected=$numbers[1]; //set variable

 if($connected==1) //if DSP is connected
  $wordconnected="yes"; //set variable
 else //if no DSP connection
  $wordconnected="no"; //set variable
 $peaklisteners=$numbers[2]; //set variable
 $maxlisteners=$numbers[3]; //set variable
 $reportedlisteners=$numbers[4]; //set variable
 $bitrate=$numbers[5]; //set variable
}

$im = ImageCreate(150,50);
$background_color = ImageColorAllocateAlpha($im,255,0,255,127);
$text_color1 = ImageColorAllocate($im,0,0,0);
$text_color2 = ImageColorAllocate($im,265,100,100);

if($success!=2 && $connected==1){
 $song=explode(" - ",$numbers[6]);
 $string1= "AF Radio (".$numbers[5]." KBPS)";
 $string2= "Artist: ".$song[0];
 $string3= "Song: ".$song[1];
 $string4= "<u>Listeners ".$numbers[0]."/".$numbers[3]." @ a peak of ".$numbers[2] . "</u>";
}
else {
 $string1= "";
 $string2= "Blah Blah Radio is currently";
 $string3= "Offline!.";
 $string4= "";
}

$px = (imagesx($im)-5*strlen($string1))/2;
ImageString($im,1,$px,5,$string1,$text_color1);
$px = (imagesx($im)-5*strlen($string2))/2;
ImageString($im,1,$px,20,$string2,$text_color1);
$px = (imagesx($im)-5*strlen($string3))/2;
ImageString($im,1,$px,30,$string3,$text_color1);
$px = (imagesx($im)-5*strlen($string4))/2;
ImageString($im,1,$px,40,$string4,$text_color2);
ImagePng($im);
ImageDestroy($im);
?>


mine doesnt use a db, it just puts the info to an image.
Crab-Apple
Can I manually create the take because the install script (below) wont create it.

CODE
<?php
//////////////////////////////////////////////////////////////////////////////
// DJ Status v1.8               //
// ©2004 Nathan Bolender www.2004design.tk         //
// Free to use on any website            //
//////////////////////////////////////////////////////////////////////////////

include ("../header.inc");
include ("../../config.php");

if(!$db = @mysql_connect("$dbhost", "$dbuser", "$dbpass"))
die('<font size=+1>An Error Occurred</font><hr>Unable to connect to the database. <BR>Check $dbhost, $dbuser, and $dbpass in config.php.');
if(!@mysql_select_db("$dbname",$db))
die("<font size=+1>An Error Occurred</font><hr>Unable to find the database <b>$dbname</b> on your MySQL server.");

$result1 = mysql_query("CREATE TABLE `currentdj` (
 `dj` int(11) NOT NULL auto_increment,
 `active` int(11) NOT NULL default '0',
 `name` text NOT NULL,
 `password` text NOT NULL,
 `address` text NOT NULL,
 `aim` text NOT NULL,
 `msn` text NOT NULL,
 `yim` text NOT NULL,
 `icq` text NOT NULL,
 `alias1` text NOT NULL,
 `alias2` text NOT NULL,
 `alias3` text NOT NULL,
 PRIMARY KEY  (`dj`)
) TYPE=MyISAM AUTO_INCREMENT=1; ");

$result2 = mysql_query("CREATE TABLE `currentdj_settings` (
 `id` int(11) NOT NULL auto_increment,
 `name` text NOT NULL,
 `setting` text NOT NULL,
 PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1; ");

$result3 = mysql_query("INSERT INTO `currentdj_settings` VALUES (1, 'Mode', '0'); ");
$result4 = mysql_query("INSERT INTO `currentdj_settings` VALUES (2, 'Display how DJ was set', '0'); ");


if (($result1 == TRUE) && ($result2 == TRUE) && ($result3 == TRUE) && ($result4 == TRUE)) {

echo "Congratulations! The script was successfully installed!<br><b>Make sure you delete the admin/install folder before continuing to use the script.</b><br>Please click continue to enter the administration panel and add your DJs. <br><a href=\"../index.php\">Continue...</a>";

} else {

echo "Sorry but the tables could not be created, please try again.";
}
include ("../footer.inc");
?>
Josh
Do you have phpmyadmin installed?
morrowasted
QUOTE (Crab-Apple @ Jul 31 2004, 11:11 PM)
Can I manually create the take because the install script (below) wont create it.


yeah, just query

CREATE TABLE `currentdj` (
`dj` int(11) NOT NULL auto_increment,
`active` int(11) NOT NULL default '0',
`name` text NOT NULL,
`password` text NOT NULL,
`address` text NOT NULL,
`aim` text NOT NULL,
`msn` text NOT NULL,
`yim` text NOT NULL,
`icq` text NOT NULL,
`alias1` text NOT NULL,
`alias2` text NOT NULL,
`alias3` text NOT NULL,
PRIMARY KEY (`dj`)
) TYPE=MyISAM AUTO_INCREMENT=1; ")

on your mysql server. you can do this through console or phpmyadmin (or some other program)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.