SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Notice: Undefined variable:

    Never had this problem before but just switched to using php my admin on a new server.

    The line in question is bolded but the error I keep getting is -

    Notice: Undefined variable: userdata in C:\Program Files\EasyPHP 3.0\www\swiftdistributors\memberspage.php on line 30
    Code:
    <?php
    
    require_once('database/database.php');
    
    $query = ("SELECT users_table.first_name, users_table.last_name, users_table.company, users_table.login_count, users_table.time_stamp, users_table.sales_contact, users_table.email, users_table.sales_contact, sales_contact_table.sales_contact, sales_contact_table.email FROM users_table, sales_contact_table WHERE users_table.sales_contact = sales_contact_table.sales_contact AND  users_table.username = '$_SESSION[username]'");
    
    $result = mysql_query($query) or die("Your login reguest has failed please contact us immediately <a href=\"mailto:webmaster@davidbrown.com\" class=\"centerlink\">contact us</a>" . $query);
    $num_rows = mysql_num_rows($result);
    if ($num_rows > 0)
    {
    while($row = mysql_fetch_assoc($result))
    {
    $logintext = <<<LOGINTEXT
    <ul class="ulmembersdetails">
    <li>Name: $row[first_name] $row[last_name]</li>
    <li>Company: $row[company]</li>
    <li>Your last login was: $row[time_stamp]</li>
    <li>You have logged in $row[login_count] times</li>
    <li>Your local sales contact is: <a href="mailto:$row[email]"  class="centerlink">$row[sales_contact]</a></li>
    </ul>
    LOGINTEXT;
    }}
    
    
    $query = ("SELECT order_sales_table.company, order_sales_table.past_orders, order_sales_table.current_orders, order_sales_table.past_sales, order_sales_table.current_sales, order_sales_table.currency, order_sales_table.last_upload, users_table.access_rights, users_table.company FROM order_sales_table, users_table WHERE order_sales_table.company = users_table.company AND users_table.username = '$_SESSION[username]'");
    
    $result = mysql_query($query) or die("Your Order &amp; Sales query has failed please contact us immediately <a href=\"mailto:webmaster@davidbrown.com\"class=\"centerlink\">contact us</a>" .$query );
    $num_rows = mysql_num_rows($result);
    if ($num_rows > 0)
    {
    while($row = mysql_fetch_assoc($result))
    {
    
    if ($row['access_rights'] == "A") {
    $adminrights = "<p class=\"p\">You have administration rights within Swift Distirbutors please use the following link if you wish to make any administration changes <a href=\"database/admincontrol/createusersform.php\" class=\"centerlink\">Admin Control Panel</a></p>";
    }
    $pastorders = number_format($row['past_orders'],2);
    $currentorders = number_format($row['current_orders'],2);
    $pastsales = number_format($row['past_sales'],2);
    $currentsales = number_format($row['current_sales'],2);
    
    
    $userdata = <<<USERDATA
    <table class="userdatatable">
      <caption>Order Data</caption>
    <tr>
    <th>Orders 2008</th>
    <th>Orders 2009</th>
    </tr>
    <tr>
    <td>$row[currency] $pastorders</td>
    <td>$row[currency] $currentorders</td>
    </tr>
    <tr>
    <td colspan="2">Order Data last updated: $row[last_upload]</td>
    </tr>
    </table>
    
    <table class="userdatatable">
      <caption>Sales Data</caption>
    <tr>
    <th>Sales 2008</th>
    <th>Sales 2009</th>
    </tr>
    <tr>
    <td>$row[currency] $pastsales</td>
    <td>$row[currency] $currentsales</td>
    </tr>
    <tr>
    <td colspan="2">Sales Data last updated: $row[last_upload]</td>
    </tr>
    </table>
    USERDATA;
    
    
    }}
    ?>
    Cheers for any help

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)
    Shouldn't there be a space between the "<" and the "U"?

  3. #3
    SitePoint Evangelist
    Join Date
    Aug 2005
    Location
    Winnipeg
    Posts
    498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <li>Name: $row[first_name] $row[last_name]</li>
    You should have single or double quotes (preferably the former) around each index unless it's a variable in which case you prefix with the $ sign.
    The only constant in software is change itself

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Shouldn't there be a space between the "<" and the "U"?
    Nope.
    You should have single or double quotes (preferably the former) around each index unless it's a variable in which case you prefix with the $ sign.
    Nope. Inside a string, $array[key] is perfectly fine, though {$array['key']} is preferred.

    I can't see how that error could be formed... $userdata isn't mentioned anywhere other than being set. You sure this is the right file?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #5
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah its the right file tried many options and still can't get it to work.

  6. #6
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Okay, I've gone through the file and written it out how I would prefer to write it, including a couple of MySQL-optimisations and removal of some un-needed code.

    This is simply as an example of what would work, and it isn't by any means telling you how to write out your code, so please take no offense by me changing it around - it's simply personal preference - but I find it easier to locate the problem if there any errors occur in it.
    PHP Code:
    <?php
    Error_Reporting
    (E_ALL);
    Ini_Set('display_errors'2);
    Require_Once(
    'database/database.php');
    $Query = <<<SQL
        SELECT
              users_table.first_name
            , users_table.last_name
            , users_table.company
            , users_table.login_count
            , users_table.time_stamp
            , users_table.sales_contact
            , users_table.email
            , users_table.sales_contact
            , sales_contact_table.sales_contact
            , sales_contact_table.email
        FROM
            users_table
                INNER JOIN
                    sales_contact_table
                ON
                    users_table.sales_contact = sales_contact_table.sales_contact
                        AND
                    users_table.username = '
    {$_SESSION['username']}'
    SQL;
    $Result MySQL_Query($Query) or die('Your login reguest has failed please contact us immediately <a href="mailto:webmaster@davidbrown.com" class="centerlink">contact us</a>' $Query);
    while(
    $Row MySQL_Fetch_Assoc($Result)){
        
    $logintext = <<<LOGINTEXT
            <ul class="ulmembersdetails">
                <li>Name: 
    {$Row['first_name']} {$Row['last_name']}</li>
                <li>Company: 
    {$Row['company']}</li>
                <li>Your last login was: 
    {$Row['time_stamp']}</li>
                <li>You have logged in 
    {$Row['login_count']} times</li>
                <li>Your local sales contact is: <a href="mailto:
    {$Row['email']}"  class="centerlink">{$Row['sales_contact']}</a></li>
            </ul>
    LOGINTEXT;
    }
    $Query = <<<SQL
        SELECT
              order_sales_table.company
            , order_sales_table.past_orders
            , order_sales_table.current_orders
            , order_sales_table.past_sales
            , order_sales_table.current_sales
            , order_sales_table.currency
            , order_sales_table.last_upload
            , users_table.access_rights
            , users_table.company
        FROM
            order_sales_table
                INNER JOIN
                    users_table
                ON
                    order_sales_table.company = users_table.company
                AND
                    users_table.username = '
    {$_SESSION['username']}'
    SQL;
    $Result MySQL_Query($Query) or die("Your Order &amp; Sales query has failed please contact us immediately <a href=\"mailto:webmaster@davidbrown.com\"class=\"centerlink\">contact us</a>" .$query );
    while(
    $Row MySQL_Fetch_Assoc($Result)){
        if (
    $Row['access_rights'] == "A") {
            
    $adminrights '<p class="p">You have administration rights within Swift Distirbutors please use the following link if you wish to make any administration changes <a href="database/admincontrol/createusersform.php" class="centerlink">Admin Control Panel</a></p>';
        }
        
    $pastorders number_format($Row['past_orders'],2);
        
    $currentorders number_format($Row['current_orders'],2);
        
    $pastsales number_format($Row['past_sales'],2);
        
    $currentsales number_format($Row['current_sales'],2);
        
    $userdata = <<<USERDATA
            <table class="userdatatable">
                <caption>Order Data</caption>
                <tr>
                    <th>Orders 2008</th>
                    <th>Orders 2009</th>
                </tr>
                <tr>
                    <td>
    {$Row['currency']} {$pastorders}</td>
                    <td>
    {$Row['currency']} {$currentorders}</td>
                </tr>
                <tr>
                    <td colspan="2">Order Data last updated: 
    {$Row['last_upload']}</td>
                </tr>
            </table>
            <table class="userdatatable">
                <caption>Sales Data</caption>
                <tr>
                    <th>Sales 2008</th>
                    <th>Sales 2009</th>
                </tr>
                <tr>
                    <td>
    {$Row['currency']} {$pastsales}</td>
                    <td>
    {$Row['currency']} {$currentsales}</td>
                </tr>
                <tr>
                    <td colspan="2">Sales Data last updated: 
    {$Row['last_upload']}</td>
                </tr>
            </table>
    USERDATA;
    }
    I get no syntax errors, though due to the obvious lack of a valid database to connect to I cannot know if there are undefined variable errors etc. By using the above code, do you get any issues?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  7. #7
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)
    I haven't used heredoc that much, but after reviewing the documentation it looks like I should change some of my code. The <<< [space] identifier "works", but will it always?

    Anyway, I'm guessing the problem might be a create - run problem. The docs say something about the line before the closing identifier needing to be a recognized newline. So if you created the script using an "\r" or "\n", and the running script is looking for the other newline, then it won't find it and the variable will be unclosed.


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
  •