SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php function not working

    Hi there i have created a php function which does this

    PHP Code:
    function clansettings()
    {
                            include(
    "dbconnect.php");
                            
    $gQuery="SELECT * FROM clansettings where csid='1'";
                            
    //excute the query
                            
    error_reporting(E_ALL);
                            
    //echo $gQuery;
                            
    $rs=mysqli_query($con,$gQuery);
                            if(!
    $rs)
                            {
                            
    $dbError="Error:Failed to executing query"
                            
    .mysqli_error($con);
                            }
                            else
                            {
                                
    $count=$rs->num_rows;
                                if(
    $count>0)
                                {
                                    
    $data=$rs->fetch_assoc();
                                    
    $ClanName=$data['ClanName'];
                                    
    $recruiting=$data['recruiting'];
                                    
    $securitylevel=$data['securitylevel'];
                                    
    $fontcolor=$data['fontcolor'];
                                    
    $startingrecruitmentrank=$data['startingrecruitmentrank'];
                                    
    $postnews=$data['postnews'];
                                    
    $promoterank=$data['promoterank'];
                                    
    $demoterequire=$data['demoterequire'];
                                    
    $disablerequire=$data['disablerequire'];
                                    
    $awardmedal=$data['awardmedal'];
                                    
    $revokemedal=$data['revokemedal'];
                                    
    $clanallance=$data['clanallance'];
                                    
    $memberspass=$data['memberspass'];
                                    
    $recordban=$data['recordban'];
                                    
    $memberpagination=$data['memberpagination'];
                                    
    $dpmemberdisplay=$data['dpmemberdisplay'];
                                    
    $visitorregistration=$data['visitorregistration'];
                                    
    $vistorforum=$data['vistorforum'];
                                    
    $backupsettings=$data['backupsettings'];
                                    
    $ShopCat=$data['ShopCat'];
                                    
    $bankinfo=$data['bankinfo'];
                                    
    $postal=$data['postal'];
                                    
    $adminemail=$data['adminemail'];
                                    
    //$license=$data['license'];
                                
    }
                            }

    and when i echo the function back this is what i echo

    PHP Code:
    clansettings(); 
    It doesnt echo anything back but when i go to my index.php page it just display this.

    PHP Code:
    NoticeUndefined variablefontcolor in C:\Program Files\xampp\htdocs\BC Clan Scripts\index.php on line 304

    Notice
    Undefined variableClanName in C:\Program Files\xampp\htdocs\BC Clan Scripts\index.php on line 304
    Hey
    ,Welcome to  


    Notice
    Undefined variablefontcolor in C:\Program Files\xampp\htdocs\BC Clan Scripts\index.php on line 320

    Notice
    Undefined variablefontcolor in C:\Program Files\xampp\htdocs\BC Clan Scripts\index.php on line 321

    Notice
    Undefined variablefontcolor in C:\Program Files\xampp\htdocs\BC Clan Scripts\index.php on line 324

    Notice
    Undefined variablefontcolor in C:\Program Files\xampp\htdocs\BC Clan Scripts\index.php on line 320

    Notice
    Undefined variablefontcolor in C:\Program Files\xampp\htdocs\BC Clan Scripts\index.php on line 321

    Notice
    Undefined variablefontcolor in C:\Program Files\xampp\htdocs\BC Clan Scripts\index.php on line 324
    Posted by
    :sadsa     Subject:sdasdsa
    sad
    Posted by
    :aS     Subject:sAA
    dSA



    Notice
    Undefined variablesecuritylevel in C:\Program Files\xampp\htdocs\BC Clan Scripts\index.php on line 341

    Notice
    Undefined variablerecruiting in C:\Program Files\xampp\htdocs\BC Clan Scripts\index.php on line 362

    Notice
    Undefined variablefontcolor in C:\Program Files\xampp\htdocs\BC Clan Scripts\index.php on line 336
    Current Clan     
    Notice
    Undefined variablefontcolor in C:\Program Files\xampp\htdocs\BC Clan Scripts\index.php on line 337 
    How can i fix that seems fine.

  2. #2
    SitePoint Evangelist catweasel's Avatar
    Join Date
    Apr 2007
    Location
    Goldfields, VIC, Australia
    Posts
    518
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well you function doesn't seem to return anything so echoing it won't print anything out..

    also.. this -
    PHP Code:
    $ClanName=$data['ClanName']; 
    $recruiting=$data['recruiting']; 
    $securitylevel=$data['securitylevel']; 
    $fontcolor=$data['fontcolor']; 
    $startingrecruitmentrank=$data['startingrecruitmentrank']; 
    $postnews=$data['postnews']; 
    $promoterank=$data['promoterank']; 
    $demoterequire=$data['demoterequire']; 
    $disablerequire=$data['disablerequire']; 
    $awardmedal=$data['awardmedal']; 
    $revokemedal=$data['revokemedal']; 
    $clanallance=$data['clanallance']; 
    $memberspass=$data['memberspass']; 
    $recordban=$data['recordban']; 
    $memberpagination=$data['memberpagination']; 
    $dpmemberdisplay=$data['dpmemberdisplay']; 
    $visitorregistration=$data['visitorregistration']; 
    $vistorforum=$data['vistorforum']; 
    $backupsettings=$data['backupsettings']; 
    $ShopCat=$data['ShopCat']; 
    $bankinfo=$data['bankinfo']; 
    $postal=$data['postal']; 
    $adminemail=$data['adminemail']; 
    $license=$data['license']; 
    could easily be changed to this-
    PHP Code:
    extract($data); 
    what is on line 304 of Scriptsindex.php?

  3. #3
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well for line 304 of index.php

    its

    PHP Code:
    echo "<font color=".$fontcolor.">Hey,Welcome to &nbsp;".$ClanName."<br/><br/>"

  4. #4
    SitePoint Evangelist catweasel's Avatar
    Join Date
    Apr 2007
    Location
    Goldfields, VIC, Australia
    Posts
    518
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh ok.. clanName and fontColor are variables being defined in your function clansettings() .. which doesn't seem to return anything.

    You are losing variable scope because the variables defined inside that function live only for that function.. nothing outside of that function will be able to access them.

    Also.. you begin by using mysqli_query . in procedural style.. then switch to using object style $rs->num_rows and $rs->fetch_assoc.

    Try passing an array to the function as a reference and then extracting the array outside the function.
    PHP Code:
    function clansettings(&$array) { 
        include(
    "dbconnect.php"); 
        
    $gQuery="SELECT * FROM clansettings where csid=1"
        if (
    $rs=mysqli_query($con,$gQuery)) {
            if(
    mysqli_num_rows($rs) > 0) { 
                
    $array mysqli_fetch_assoc($rs); 
            } 
        }
    }

    $data = array();
    clansettings($data);
    extract ($data); 

  5. #5
    SitePoint Evangelist catweasel's Avatar
    Join Date
    Apr 2007
    Location
    Goldfields, VIC, Australia
    Posts
    518
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by catweasel View Post
    Try passing an array to the function as a reference and then extracting the array outside the function.
    Or for that matter you could just return an array from the function -
    PHP Code:
    function clansettings() { 
        include(
    "dbconnect.php"); 
        
    $gQuery="SELECT * FROM clansettings where csid=1"
        if (
    $rs=mysqli_query($con,$gQuery)) {
            if(
    mysqli_num_rows($rs) > 0) { 
                
    $data mysqli_fetch_assoc($result);
                return 
    $data;
            }
            else return 
    0;
        }
        else return 
    false;
    }

    $data clansettings();
    if (
    is_array ($data))
        
    extract($data); 

  6. #6
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks just letting you all know i have got this sorted now thanks for the help.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •