Issues with Functions

Discussion in 'PHP' started by aalicki, May 11, 2009.

  1. #1
    This code snippet, when called, displays a news alert on a page. However, when the News Alert is turned off (click here to turn off), the database field doesn't change, and thus, the code doesn't work.

    
    function news_alert($m_alert_banner, $m_id){
    
    	if($m_alert_banner == "Yes") {
    		$news_alert = mysql_query("SELECT * FROM `TABLE`");
    		while ($c = mysql_fetch_array($news_alert)) { 
    
    	echo ("<center><div class=\"message loginerror\">$c[news_alert]<br/> <a href=\"?act=off\">Turn Off News Alert</a></center> <br/><center>");  }
    
    	if ($_GET['act'] == "off") { echo("<div class=\"message success\">You've turned off the News Alert. $m_id</div>");
    		mysql_query("UPDATE `TABLE` SET `alert_banner` = 'No' WHERE `id` = '$m_id'"); }
    	}
    return $news_alert_banner;
    }
    PHP:
    That is the function, and here is how I'm calling it.

    news_alert("Yes", "$m_id");
    PHP:
     
    aalicki, May 11, 2009 IP
  2. monster64

    monster64 Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try calling it like:

    news_alert("Yes", $m_id);
    PHP:
     
    monster64, May 11, 2009 IP
  3. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You only need to put quotes around a string, not the variable. Meaning remove the quote from the second parameter since you're passing it as a variable and not a string.
     
    kblessinggr, May 11, 2009 IP