DB connection isn't working inside function.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • flydev
    New Member
    • Feb 2008
    • 33

    DB connection isn't working inside function.

    I'm having an issue here I have never seen before...

    I have a several PHP files, template.php, db.php and functions.php...db.php and functions.php are included in template.php in that order. When I try to call a function from functions.php, the MySQL query fails with:

    "Access denied for user 'airfront'@'loc alhost' (using password: NO)"
    When I remove the function and place the code inline instead, it works fine...

    Here is the function.
    Code:
    function siteMsg($msg){						// Get the msg
    	$sql = "SELECT *
    			FROM siteMessages
    			WHERE code = '" . $msg . "'";
    	$result = mysql_query($sql)or die(mysql_error());
    	$array = mysql_fetch_array($result);
    	
    	$dString = "<div style='vertical-align: middle; width: 620px; padding-left: 5px; float: left; padding-top: 10px; ";
    	
    	switch($array['type']){
    		case "red":
    			$dString .= "color: #FF0000; ";
    			$dString .= "font-weight: bold; ";
    			$dString .= "text-size: 10px; ";
    			$dString .= "text-align: left; ";
    			break;
    		case "green":
    			$dString .= "color: #009900; ";
    			$dString .= "font-weight: bold; ";
    			$dString .= "text-size: 10px; ";
    			$dString .= "text-align: left; ";
    			break;
    	}
    	
    	$dString .= ">";
    	$dString .= "<ul style='list-style-type: none; padding: 0px; margin: 0px;'>";
    	$dString .= "  <li style='float: left; padding-left: 0px; width: 40px; display: inline;'><img src='images/alert_" . $array['type'] . ".png' /></li>";
    	$dString .= "  <li style='padding: 0px; width: 570px; display: inline;'>" . $array['msg'] . "</li>";
    	$dString .= "</ul>";
    	$dString .= "</div>";
    	
    	return $dString;
    }
  • flydev
    New Member
    • Feb 2008
    • 33

    #2
    I found my error, mod can delete this post, thanks!

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hi.

      I'm glad you solved the problem!

      Would you mind sharing the solution?
      In case somebody else is look for a solution to a similar problem.

      Comment

      • flydev
        New Member
        • Feb 2008
        • 33

        #4
        Well, it was a real silly mistake, make sure you dont have any "mysql_close(); " lines creeping around in one of your includes...haha .

        Comment

        Working...