Jump to content

Recommended Posts

Hi

 

We moved a site that was developed by outsource company from old to new server and seem to be experiencing some issues on the new server. The products don’t show up anymore and no changes have been done on the code. When I turn errors on like http://mlungisi-001-site1.smarterasp.net/products.php there are some notices but surprisingly it worked on the old server.

 

Windows 2008, IIS7 Server

 

Errors turned on

 

Notice: A session had already been started - ignoring session_start() in H:\root\home\mlungisi-001\www\site1\libs\products.php on line 27

session_start();

Notice: Undefined variable: iAUID in H:\root\home\mlungisi-001\www\site1\libs\users.php on line 73

GetAU($iAUID, $AUID, $Email, $Firstname, $Surname, $COID, $CellNo, $PWord, $Active_Tag);

Notice: Undefined offset: 0 in H:\root\home\mlungisi-001\www\site1\libs\users.php on line 74

GetAU($iAUID, $AUID, $Email, $Firstname, $Surname, $COID, $CellNo, $PWord, $Active_Tag);

Notice: Undefined offset: 0 in H:\root\home\mlungisi-001\www\site1\libs\users.php on line 75

$_SESSION['uSurName'] = $Surname[0];

Notice: Undefined index: uUserTypeID in H:\root\home\mlungisi-001\www\site1\libs\products.php on line 1244

if ($_SESSION['uUserTypeID'] == 2)

I have tried to kill sessions before starting a new one but that didn’t help either. I am caught between a latch and a door, don’t know whether its code issue or PHP configurations or MySQOL. Please share ideas

 

Attachments

 

Products.php

 

Users.php

users.php

products.php

 

Notice: A session had already been started - ignoring session_start() in H:\root\home\mlungisi-001\www\site1\libs\products.php on line 27

session_start();

 Something some where else is already started the session and this line is trying to start it too. You should be able to safely delete that from line 27 from products.php.

 

 

Notice: Undefined offset: 0 in H:\root\home\mlungisi-001\www\site1\libs\users.php on line 74

Notice: Undefined offset: 0 in H:\root\home\mlungisi-001\www\site1\libs\users.php on line 75

Replace lines 74 and 75 to the following

        if(isset($Firstname) && isset($Surname))
        {
            $_SESSION['uFirstName'] = $Firstname[0];
            $_SESSION['uSurName'] = $Surname[0];
        }

 

Notice: Undefined variable: iAUID in H:\root\home\mlungisi-001\www\site1\libs\users.php on line 73

GetAU($iAUID, $AUID, $Email, $Firstname, $Surname, $COID, $CellNo, $PWord, $Active_Tag);

It is hard to recommend what to do for the solving the above error as I do not know how/where those variables are being defined, this the problem when variables are defined as global. You could try changing $iAUID to $_SESSION['uAUID'] however I do not know if this will break the GetAU function. 

 

If your site is running as it should then edit your servers php config so displayer_errors directive is set to Off.

Edited by Ch0cu3r

Thanks, I am testing on local server and still the site can display products, there to many errors on $_SESSION lines. I somehow wonder how it worked on the old server? unfortunately the server is gone and cant go back check evenrything. Can a MySQL or PHP confirg error cause this?

you need to actually troubleshoot and find out why your page isn't producing the result you expect. making individual error messages go-away won't necessarily find the cause of the problem. you need to narrow down and find out the exact point in the code that is responsible for producing the display of the products that the problem starts at, to find out what is causing it. the code you have posted is just the functions that are being called, the main code that should be setting variables and calling the functions is where the actual problem is at.

 

for example, the Undefined offset: 0 error for the $_SESSION['uFirstName'] = $Firstname[0]; statement. that's just a follow-on error because the query is missing the the $iAUID value and the query didn't return any rows(s) to fetch.

 

you may want to consider rewriting this code, it is amateurish, brute-force built, contains little or no validation or error checking, and is killing your database server with making/closing a database connection in each function that runs a query (this alone will result in a noticeably longer page generation time.)

i've looked at part of your code, where some of posted errors in the users.php file are at, specifically the LoggedInAndLogo() function, and the errors are due to meaningless nonsense code. this also means that the errors in this section where always present in the code but were hidden due to php's error_reporting/display_errors settings and aren't even relevant to the problem of products not displaying.

 

$_SESSION['uAUID'] is the logged in user id. for a non-logged in visitor, this is set to a 1. the code then tests $_SESSION['uAUID']. if it is a 1, it displays content with "Hi Visitor" in it. if it is greater than a 1, it displays content with "Hi " . $_SESSION['uFirstName']." in it. this second block of code/content only differs in the visitor/username text and is repetitive/copy/pasted/bruit-force-built crap code.

 

the three lines of code -

        GetAU($iAUID, $AUID, $Email, $Firstname, $Surname, $COID, $CellNo, $PWord, $Active_Tag);
        $_SESSION['uFirstName'] = $Firstname[0];
        $_SESSION['uSurName'] = $Surname[0];

 

don't even belong in this. for a guest/visitor that isn't logged in, there's no input value present that says who he is and that code is meaningless at that point and won't ever produce any result, except for the php errors is generates. for someone who's logged in, those values have already been set in the session variables (wherever the login processing logic is at.)

continuing on (at this point, this reply is completely off topic, because the errors listed for the users.php file have nothing to do with any problem of displaying anything), the LoggedInAndLogo() function, rewritten without the redundant code and without the nonsense code, with some comments to explain what it is doing, would look like this -

function LoggedInAndLogo($Menu = 0,$MainMenu = 0, $Promo = 0)
{
    // if no user id, default to 1, guest/visitor
    if (!isset($_SESSION['uAUID']))
    {
        $_SESSION['uAUID'] = 1;
    }

    // setup guest/visitor display
    if ($_SESSION['uAUID'] == 1)
    {
        // if no session quote id and there is a cookie, get quote id from the cookie
        if ((!isset($_SESSION['QuoteID'])) && (isset($_COOKIE['quoteid'])))
        {
            $_SESSION['QuoteID'] = (int)$_COOKIE['quoteid'];
        }
        $display_name = 'Visitor';
    }

    // setup logged in user display
    if ($_SESSION['uAUID'] > 1)
    {
        // get quote(s) for this user
        AUQuote($_SESSION['uAUID'], $gqQuoteID, $gqAUID, $gqTStamp, $gqTDate, $gqTQty, $gqTotal, $gqREF, $gqQuoteStatusID, $gqHQDate, $gqEmail, $gqFirstname, $gqSurName, $gqQuoteStatus, $gqCOID, $gqCompany);
        // loop over quotes for this user
        for ($p = 0; $p < count($gqQuoteID); $p++)
        {
            // if any are 'New', use the last new one's id as the quote id
            if ($gqQuoteStatus[$p] == 'New')
            {
                $_SESSION['QuoteID'] = $gqQuoteID[$p];
            }
        }
        $display_name = $_SESSION['uFirstName'];
    }

    // common/display code -
    print "<div style='margin:0px;padding: 0px;position:relative'>";
    print "<a href='index.php' target='_self'>";
    print "<img name='Gestures_r1_c6' src='images/Gestures_r1_c6.png' width='283' height='149' border='0' id='Gestures_r1_c6' alt='' /></a>";
    print "<div style='margin:0px;padding: 0px;position:absolute;top:134px;left:0px;text-align:center;width:230px;' class='PurpleBold'>   ";
    
    if (isset($_SESSION['QuoteID']))
    {
        GetQuoteStatus($_SESSION['QuoteID'], $QuoteStatusID, $QuoteStatus);
        if ($QuoteStatus == 'New')
        {
            GetQuoteItems($_SESSION['QuoteID'], $QuoteProdID, $QuoteID, $QuoteRef, $ProdID, $ProdCode, $Product, $PColorID, $PColor, $Qty, $Price, $Active_Tag);
        }
        for ($i = 0; $i < count($QuoteProdID); $i++)
        {
            $TotalQnty = $TotalQnty + $Qty[$i];
            $TotalPrice = $TotalPrice + ($Price[$i]*$Qty[$i]);
        }
    } else {
        $TotalQnty = 0;
        $TotalPrice = 0.00;
    }

    print "<div align='left' style='padding-left:10px'>";
    print "
        <table width='100%' border='0' cellspacing='0' cellpadding='0'>
            <tr>
                <td colspan='2'><div align='center' class='PurpleBold'>Hi $display_name <span class='FormBoldText'>| </span><a href='login.php?signout' ><span class='GreyText12'>Sign out </span></a></div></td>
            </tr>
            <tr>
                <td colspan='2'><table width='270' border='0' cellspacing='5' cellpadding='0'>
            <tr>
                <td><table width='260' style='border-style:solid; border-width:thin' align='center' cellpadding='0' cellspacing='0' bordercolor='#64358C'>
            <tr>
                <td bordercolor='#FFFFFF' bgcolor='#FFFFFF'><table width='100%' border='0' cellspacing='2' cellpadding='0'>
            <tr>
                <td width='50%' class='PurpleWish'>Wishlist:</td>
                <td width='20%' class='BlackBoldText'><div style='display:inline' id='your_basket'>".$TotalQnty."</div></td>
                <td width='30%' rowspan='2' valign='bottom'><form action='product.php' method='post'><input name='Checkout' type='submit' class='BottomBanner' id='Checkout' value='Submit Quote' /></form></td>
            </tr>";

    print " </table></td>
        </tr>
        </table></td>
        </tr>
        </table></td>
        </tr>
        </table>";

    print "         </div>";

    print "<div align='right' class='PurpleBold' style='padding-left:15px;padding-top:5px;display:none' id=login_form'>
        <form id='login_form' name='login_form' method='post' action='login.php'>
        <table border='0' align='center' cellpadding='0' cellspacing='0'>
        <tr>
        <td class='PurpleBold'><div align='right'>Email: </div></td>
        <td><label>
        <input name='email' type='text' class='FormBoldText' id='dealer-username' />
        </label></td>
        <td></td>
        </tr>
        <tr>
        <td class='PurpleBold'><div align='right'>Password: </div></td>
        <td><input name='password' type='text' class='FormBoldText' id='dealer-password' /></td>
        <td><input name='login' type='submit' class='PurpleBold' id='Login' value='Login' /></td>
        </tr>
        </table>
        </form>
        </div>";

    print "<div style='text-align:left' >";

    if ($Menu == 1)
    {
        ProductGroupMenu();
    }

    if ($MainMenu == 1)
    {
        MainMenuBox();
    }

    if ($Promo == 1)
    {
        PromoBox();
    }

    print "</div>";
    print "</div>";
    print "</div>";
}

that's quitter talk (or try it and throw it away if it doesn't work programming talk.)

 

 

you need to actually troubleshoot and find out why your page isn't producing the result you expect.

 

none of the php detected error messages posted so far have anything to do with products not being displayed. you would need to start with whatever main page is responsible for displaying the products and determine why it isn't doing what you expect.  if you want us to help, you will need to post the relevant code and any errors, symptoms, or incorrect output you are getting from the code.

 


 

here's more off topic info - i did look at the products.php code closer and it is also full of repetitive code that only differs in the stored procedure it is calling in the database. of the 1200+ lines of code in it, there's probably only about 400 unique lines of code that could have been simplified and consolidate into selecting the desired query statement and calling common code to run the query and handle the result from the query.

 

as to the database connection problem. the code needs to open one database connection at the start (in the main code) and pass that connection into the functions that need it and doesn't close the connection at all (php automatically destroys all resources used by a script when the script ends.) since the functions in either the users.php or products.php file are/should be related to users or products, the functions in each of those files should really be part of a class, in which case you can just pass the database connection into the instance of each class and store it and reference it as a property in the class.

Edited by mac_gyver
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.