Im trying to make a function that retrieves a value from the db, but i`m getting the error var is undefined. I have read that you could set the php error level lower, but that looks like bad practice to me.
I have tried to pass de undefined var as param, I have tried to give it a standard value. but I dont seem to understand the concept here.
here is the code: $Playlist is undefined, something went wrong is printed to the screen
function returnPlaylistIndex(){
$con = mysql_connect("localhost", "user", "pass") or die(mysql_error());
if(!$con){
mysql_select_db("dbname") or die(mysql_error());
$result = mysql_query("SELECT * FROM dbname limit 1");
while($row = mysql_fetch_array($result))
{
$PlayList = $row['playlistIndex'];
}
mysql_close($con);
}
if(isset($Playlist)){
echo $Playlist."<br />";
return $Playlist;
} else {
echo "something went wrong while quering";
}
}
any help is appreciated
SELECT * FROM dbname limit 1is "dbname" just a typo for your example here? That should be the table you are selecting from.dbnamewhich seems to be your database name, not a table?