Functions and Variables
Posted: Fri Jan 16, 2004 5:56 am
I have this code, where the variables are clearly defined, yet, the stupid function cannot read them. I get an undefined variable!!
Code: Select all
<?php
$dbname = "musicdatabase";//Set this to your database name
$cook = "sitemusic";//Set this to the cookie name
$table = "musictable";//Set this to the table name
$menupage = "pickmusic.php";//Set this to the page where the music menu will be present
$musicpage = "playmusic.php";//Set this to the page where the music will be played from
$addmusicpage = "addmusic.php";//Set this to the page where you can add music
$addmusicpageform = "addmusicform.php";//Set this to the form of where you can add music
$cookiepage = "cookie.php";//Set this to the page where it processes the data and puts it into a cookie
$deletemusicpage = "deletemusic.php";//Set this to the page where you can delete music
$deletemusicpageform = "deletemusicform.php";//Set this to the form of where you can delete music
$loop = "true";//If you want the music to play foreever, then make this true. If not, then set it to false
$autostart = "true";//If you want the music to play automatically, then set this to true. If you don't, set it to false
$visible = "true";//Keep this true if you want to allow the user to stop, pause and restart the song. BEWARE, if this is set to false, many people will NOT like your site, as it does not allow the user to disable the music. Also, the only way to disable the music when this value is set to false, is to stop the page. By stopping it, you also stop all animated images (.gif) and perhaps maybe even stop your Javascript
function playmusic() {
if ( isset($_COOKIE[$cook]) == true ) {//Tests to see if the cookie exists
$cookiename = $_COOKIE[$cook];//Assigns the cookie into an easier to manage variable
if ( $cookiename == "none" ) {
return "<center>You have selected to have no music. <br>";//Displays if the person has selected to not play any music.
} else {
if ($db = sqlite_open($dbname, 0666, $sqliteerror)){//Tries to open the database.
$result = sqlite_query($db, "select * from $table where cookiename = '$cookiename'");//Selects everything from the table.
$result = sqlite_fetch_array($result);
return '<center> <embed src="'.stripslashes($result['url']).'" visible="'.$visible.'" autostart="'.$autostart.'" loop="'.$loop.'"><br>Click <a href="'.$menupage.'">here</a> to pick another song.';
} else {
return ($sqliteerror);//If the database could not be opened, it will return this error
}//Closes the database opening if statement (By default, its on line
}//Closes the if statement that checks to see if the cookie contains the value "none" (By default, its on line 5)
} elseif ( isset($_COOKIE[$cook]) == false ) {
return header('Location: '.$menupage);//Redirects the user to pick a song, if they didn't before.
}//Closes the cookie checking if statement (By default, its on line 3)
}
?>