0

I am recieving a notice(s) multiple times when running a file:

Notice: Undefined index: Telephone in C:\xampp\htdocs\demo\nest_Demo_thrasher.php on line 111
Notice: Undefined index: eMail in C:\xampp\htdocs\demo\nest_Demo_thrasher.php on line 112

I have researched this and the ways to solve it. Most ways involve isset it seems, but none of my code in this example use Get.

Note: This code comes from a class I am taking on-line. I did not write the code. I have noticed during the class that the instructor has presented us files to download that contain obvious errors. When he runs this particular file he gets no notices like I am getting.

I also suspect that this has something directly to do with the DB - When I examine the structure of a particular table, it does not contain Telephone or Email rows to save data in, but all of the other necessary rows are there. Again, he created the DB/tables, not me. Is it possible that he forgot these rows and that is why I am getting these notices?

If the code runs and tries to store/retrieve data from rows that do not exist, that would be a major over-site, correct?

Here is his code:

`

<?php
/*

*   File:           nest_Demo_thrasher.php
*   By:         TMIT
*   Date:       2010-06-01
*
*   This script demonstrates in-elegant database thrashing
*       with a nested processing loop
*       
*
*=========================================================================
*/

{       //  Secure Connection Script
if ($dbSuccess) {

    {  //   Style declarations  
    echo '<h1>All Persons by Company</h1>';


    //      Company SQL
    $tCompany_SQLselect = "SELECT tCompany.ID AS companyID, ";      
    $tCompany_SQLselect .= "tCompany.preName, tCompany.Name, tCompany.RegType ";
    $tCompany_SQLselect .= "FROM tCompany ";

    $tCompany_SQLselect .= "ORDER BY tCompany.Name, tCompany.preName, tCompany.ID ";

    $tCompany_SQLselect_Query = mysql_query($tCompany_SQLselect);

    {   //  while  more company records

            while ($rowCompany = mysql_fetch_array($tCompany_SQLselect_Query, MYSQL_ASSOC)) {

                $CompanyID = $rowCompany['companyID'];
                $CompanypreName = $rowCompany['preName'];
                $CompanyName = $rowCompany['Name'];
                $CompanyRegType = $rowCompany['RegType'];

                $CompanyFullName = trim($CompanypreName." ".$CompanyName." ".$CompanyRegType);
                echo '<h2 '.$indent50.'>'.$CompanyFullName.'</h2>';

                echo '<div '.$indent100.'>';
            echo "<table border='1'>";
                echo "<tr>";

                    echo "<td>#</td>";
                    echo "<td>Salutation</td>";
                    echo "<td>FirstName</td>";
                    echo "<td>LastName</td>";
                    echo "<td>Telephone</td>";
                    echo "<td>eMail</td>";

                echo "</tr>";  

                {   //  Person Table for companyID

                        {//     Person SQL
                            $tPerson_SQLselect = "SELECT  ";
                            $tPerson_SQLselect .= "tPerson.ID AS personID, ";   
                            $tPerson_SQLselect .= "tPerson.Salutation, ";   
                            $tPerson_SQLselect .= "tPerson.FirstName, tPerson.LastName ";   
                            $tPerson_SQLselect .= "FROM tPerson ";
                            $tPerson_SQLselect .= "WHERE tPerson.CompanyID = ".$CompanyID." ";      
                            $tPerson_SQLselect .= "ORDER BY tPerson.LastName, tPerson.FirstName ";

                            $tPerson_SQLselect_Query = mysql_query($tPerson_SQLselect);
                        //      end person SQL
                        }

                        $currentCompanyID = -1;
                        $indx = 0;
                        echo '<div '.$textFont.'>';

                        {   //  while  more person records
                                while ($row = mysql_fetch_array($tPerson_SQLselect_Query, MYSQL_ASSOC)) {

                                    $personID = $row['personID'];
                                    $Salutation = $row['Salutation'];
                                    $FirstName = $row['FirstName'];
                                    $LastName = $row['LastName'];
                                    $Telephone = $row['Telephone'];
                                    $eMail = $row['eMail'];

                                    {   //      Create and format a row for each person
                                    if (($indx % 2) == 1) {$rowClass = $trOdd; } else { $rowClass = $trEven; }
                                    echo '<tr '.$rowClass.'>';

                                        echo "<td>".$personID."&nbsp;</td>";       //  this is NOT  tPerson.ID
                                        echo "<td>".$Salutation."&nbsp;</td>";
                                        echo "<td>".$FirstName."&nbsp;</td>";
                                        echo "<td>".$LastName."&nbsp;</td>";
                                        echo "<td>".$Telephone."&nbsp;</td>";
                                        echo "<td>".$eMail."&nbsp;</td>";

                                    echo "</tr>";
                                    //      END:  Create and format a row for each person
                                    }   
                                    $indx++;
                                }

                        //      END:   //   while  more person records
                        }       
                //  END: Person Table for companyID         
                }               

                echo "</table>";
                echo '</div>';
            }
    //  END: while more company records
    }  


    echo '</div>';

    mysql_free_result($tPerson_SQLselect_Query);        
}

?>

`

2
Contributors
7
Replies
20
Views
2 Years
Discussion Span
Last Post by pritaeas
1

Telephone and email are not selected in the query, but the code is trying to get their value on line 82/83.

0

Pritaeas:

Yes, I noticed that earlier also, I believe. This should be happening around lines 62-63? I noticed earlier that both the Telephone and Email are missing directly after tPerson.LastName on line 62. Is that correct, what I am saying about this?

I tried adding both Telephone and Email after tPerson.LastName (as tPerson.Telephone and tPerson.eMail earlier but ran into some other problem that I cannot remember at the moment.)

Thank you for you assistance.

0

When I add tPerson.Telephone and tPerson.eMail on lines 63,64 (And, I added Telephone and eMail rows to the table as well) I receive:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\demo\nest_Demo_thrasher.php on line 110

(This warning is the one I referred to in my last post that I could not remember from earlier today)

I am not sure what to make of this now.

Reposting updated code:

`

<?php
/*

*   File:           nest_Demo_thrasher.php
*   By:         TMIT
*   Date:       2010-06-01
*
*   This script demonstrates in-elegant database thrashing
*       with a nested processing loop
*       
*
*=========================================================================
*/

{       //  Secure Connection Script
if ($dbSuccess) {

    {  //   Style declarations  
    echo '<h1>All Persons by Company</h1>';


    //      Company SQL
    $tCompany_SQLselect = "SELECT tCompany.ID AS companyID, ";      
    $tCompany_SQLselect .= "tCompany.preName, tCompany.Name, tCompany.RegType ";
    $tCompany_SQLselect .= "FROM tCompany ";

    $tCompany_SQLselect .= "ORDER BY tCompany.Name, tCompany.preName, tCompany.ID ";

    $tCompany_SQLselect_Query = mysql_query($tCompany_SQLselect);

    {   //  while  more company records

            while ($rowCompany = mysql_fetch_array($tCompany_SQLselect_Query, MYSQL_ASSOC)) {

                $CompanyID = $rowCompany['companyID'];
                $CompanypreName = $rowCompany['preName'];
                $CompanyName = $rowCompany['Name'];
                $CompanyRegType = $rowCompany['RegType'];

                $CompanyFullName = trim($CompanypreName." ".$CompanyName." ".$CompanyRegType);
                echo '<h2 '.$indent50.'>'.$CompanyFullName.'</h2>';

                echo '<div '.$indent100.'>';
            echo "<table border='1'>";
                echo "<tr>";

                    echo "<td>#</td>";
                    echo "<td>Salutation</td>";
                    echo "<td>FirstName</td>";
                    echo "<td>LastName</td>";
                    echo "<td>Telephone</td>";
                    echo "<td>eMail</td>";

                echo "</tr>";  

                {   //  Person Table for companyID

                        {//     Person SQL
                            $tPerson_SQLselect = "SELECT  ";
                            $tPerson_SQLselect .= "tPerson.ID AS personID, ";   
                            $tPerson_SQLselect .= "tPerson.Salutation, ";   
                            $tPerson_SQLselect .= "tPerson.FirstName, tPerson.LastName ";

                            $tPerson_SQLselect .= "tPerson.Telephone, ";
                            $tPerson_SQLselect .= "tPerson.eMail, ";


                            $tPerson_SQLselect .= "FROM tPerson ";
                            $tPerson_SQLselect .= "WHERE tPerson.CompanyID = ".$CompanyID." ";      
                            $tPerson_SQLselect .= "ORDER BY tPerson.LastName, tPerson.FirstName ";

                            $tPerson_SQLselect_Query = mysql_query($tPerson_SQLselect);
                        //      end person SQL
                        }

                        $currentCompanyID = -1;
                        $indx = 0;
                        echo '<div '.$textFont.'>';

                        {   //  while  more person records
                                while ($row = mysql_fetch_array($tPerson_SQLselect_Query, MYSQL_ASSOC)) {

                                    $personID = $row['personID'];
                                    $Salutation = $row['Salutation'];
                                    $FirstName = $row['FirstName'];
                                    $LastName = $row['LastName'];
                                    $Telephone = $row['Telephone'];
                                    $eMail = $row['eMail'];

                                    {   //      Create and format a row for each person
                                    if (($indx % 2) == 1) {$rowClass = $trOdd; } else { $rowClass = $trEven; }
                                    echo '<tr '.$rowClass.'>';

                                        echo "<td>".$personID."&nbsp;</td>";       //  this is NOT  tPerson.ID
                                        echo "<td>".$Salutation."&nbsp;</td>";
                                        echo "<td>".$FirstName."&nbsp;</td>";
                                        echo "<td>".$LastName."&nbsp;</td>";
                                        echo "<td>".$Telephone."&nbsp;</td>";
                                        echo "<td>".$eMail."&nbsp;</td>";

                                    echo "</tr>";
                                    //      END:  Create and format a row for each person
                                    }   
                                    $indx++;
                                }

                        //      END:   //   while  more person records
                        }       
                //  END: Person Table for companyID         
                }               

                echo "</table>";
                echo '</div>';
            }
    //  END: while more company records
    }  


    echo '</div>';

    mysql_free_result($tPerson_SQLselect_Query);        
}

?>

`

0

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\demo\nest_Demo_thrasher.php on line 110

Line 65 has a comma at the end, remove it. It makes the query invalid.

Edited by pritaeas

0

Pritaeas:

Okay, Thank you.

I have not tried it yet, but what I do not understand is, for example, (Line 61)

`

$tPerson_SQLselect .= "tPerson.Salutation, ";  

`

has a comma after tPerson.Salutation. What is the exact difference? Should they all not have the comma?

Upadate: I removed the comma following tPerson.eMail on line 65 - Saved - Ran - Am getting same errors in regards to Telephone and eMail as before.

I appreciate your help,
Matthew

0

Fixed!

The error in the code was in line 62 - There was a comma required after tPerson.LastName.

Thank you so much for your help and I have learned something useful today.

Solved.

0

Should they all not have the comma?

A comma is a list separator and should be in between column values you want to select. It should not come after the last one which is just before the FROM clause. You can see the SELECT definition here.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.