Notice: Undefined index: Error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jsgoodrich@gmail.com

    Notice: Undefined index: Error

    I am looking for some help if anyone can lend a hand.

    I have a simple php website that displays a table from my mysql
    database.

    To prep for my MCSE I moved my home server to Windows 2003 Standard, I
    installed mysql and php 5 to run some of my databases and websites.

    Under Linux the site worked fine, under windows I keep getting Notice
    Undefined Index error on line 67

    I have went back to the basics just pull the data then display and
    still get the same error.

    60 $sql = "SELECT * from newschool ORDER BY State, CollNam";
    61
    62 $result = mysql_query($sq l, $dbcnx) or die(mysql_error ());
    63 $number_of_rows = mysql_num_rows( $result);
    64
    65 while ($newArray = mysql_fetch_arr ay($result)) {
    66
    67 $id = $newArray['id'];
    68 $testField = $newArray['testField'];
    69
    70 echo "The ID is $id and the text is $testField <br>";


    Anyone have any thoughts?

  • Schraalhans Keukenmeester

    #2
    Re: Notice: Undefined index: Error

    jsgoodrich@gmai l.com wrote:
    I am looking for some help if anyone can lend a hand.
    >
    I have a simple php website that displays a table from my mysql
    database.
    >
    To prep for my MCSE I moved my home server to Windows 2003 Standard, I
    installed mysql and php 5 to run some of my databases and websites.
    >
    Under Linux the site worked fine, under windows I keep getting Notice
    Undefined Index error on line 67
    >
    I have went back to the basics just pull the data then display and
    still get the same error.
    >
    60 $sql = "SELECT * from newschool ORDER BY State, CollNam";
    61
    62 $result = mysql_query($sq l, $dbcnx) or die(mysql_error ());
    63 $number_of_rows = mysql_num_rows( $result);
    64
    65 while ($newArray = mysql_fetch_arr ay($result)) {
    66
    67 $id = $newArray['id'];
    ^^
    id, without a $, is a constant. Yet you probably haven't defined that in
    your code prior to using it. (I suspect this is a typo though, yes?)
    If you have error reporting set to E_ALL, besides warnings and errors,
    you'll get notices as well.

    HTH

    Sh.

    Comment

    • Schraalhans Keukenmeester

      #3
      Re: Notice: Undefined index: Error

      Schraalhans Keukenmeester wrote:
      jsgoodrich@gmai l.com wrote:
      >I am looking for some help if anyone can lend a hand.
      >>
      >I have a simple php website that displays a table from my mysql
      >database.
      >>
      >To prep for my MCSE I moved my home server to Windows 2003 Standard, I
      >installed mysql and php 5 to run some of my databases and websites.
      >>
      >Under Linux the site worked fine, under windows I keep getting Notice
      >Undefined Index error on line 67
      >>
      >I have went back to the basics just pull the data then display and
      >still get the same error.
      >>
      >60 $sql = "SELECT * from newschool ORDER BY State, CollNam";
      >61
      >62 $result = mysql_query($sq l, $dbcnx) or die(mysql_error ());
      >63 $number_of_rows = mysql_num_rows( $result);
      >64
      >65 while ($newArray = mysql_fetch_arr ay($result)) {
      >66
      >67 $id = $newArray['id'];
      ^^
      id, without a $, is a constant. Yet you probably haven't defined that in
      your code prior to using it. (I suspect this is a typo though, yes?)
      If you have error reporting set to E_ALL, besides warnings and errors,
      you'll get notices as well.
      >
      HTH
      >
      Sh.
      >
      Skip that, I'm not awake yet.
      Is 'id' a valid field in your db?
      Try var_dump($newAr ray) to see what is returned from the db.

      Comment

      • Vince Morgan

        #4
        Re: Notice: Undefined index: Error

        <jsgoodrich@gma il.comwrote in message
        news:1177479731 .766290.149490@ r35g2000prh.goo glegroups.com.. .
        63 $number_of_rows = mysql_num_rows( $result);
        64
        65 while ($newArray = mysql_fetch_arr ay($result)) {
        You are certain that "id" is the field name?
        If so you could try,
        mysql_fetch_arr ay($result, MYSQL_ASSOC)) .
        66
        67 $id = $newArray['id'];
        68 $testField = $newArray['testField'];
        69
        70 echo "The ID is $id and the text is $testField <br>";
        >
        >
        Anyone have any thoughts?
        >
        Vince


        Comment

        • Man-wai Chang

          #5
          Re: Notice: Undefined index: Error

          65 while ($newArray = mysql_fetch_arr ay($result)) {
          67 $id = $newArray['id'];
          68 $testField = $newArray['testField'];
          You should use fetch_assoc() if the index is a string ('id') rather than
          a number(0,1,2,3. ..).

          --
          iTech Consulting Services Limited
          Expert of ePOS solutions
          Website: http://www.itech.com.hk (IE only)
          Tel: (852)2325 3883 Fax: (852)2325 8288

          Comment

          • Jerry Stuckle

            #6
            Re: Notice: Undefined index: Error

            jsgoodrich@gmai l.com wrote:
            I am looking for some help if anyone can lend a hand.
            >
            I have a simple php website that displays a table from my mysql
            database.
            >
            To prep for my MCSE I moved my home server to Windows 2003 Standard, I
            installed mysql and php 5 to run some of my databases and websites.
            >
            Under Linux the site worked fine, under windows I keep getting Notice
            Undefined Index error on line 67
            >
            I have went back to the basics just pull the data then display and
            still get the same error.
            >
            60 $sql = "SELECT * from newschool ORDER BY State, CollNam";
            61
            62 $result = mysql_query($sq l, $dbcnx) or die(mysql_error ());
            63 $number_of_rows = mysql_num_rows( $result);
            64
            65 while ($newArray = mysql_fetch_arr ay($result)) {
            66
            67 $id = $newArray['id'];
            68 $testField = $newArray['testField'];
            69
            70 echo "The ID is $id and the text is $testField <br>";
            >
            >
            Anyone have any thoughts?
            >
            Don't worry about those who are telling you to use mysql_fetch_ass oc().
            Your code is just fine; the default for mysql_fetch_arr ay() is to
            fetch both numeric and associative indicies. It may just be a little
            slower than mysql_fetch_ass oc(), but you'll never notice the difference.

            As for your problem - it looks like you don't have a column named 'id'
            in the `newschool` table. Perhaps when you created the database here
            you named it something else (or had a finger check)?

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • Man-wai Chang

              #7
              Re: Notice: Undefined index: Error

              Don't worry about those who are telling you to use mysql_fetch_ass oc().
              Your code is just fine; the default for mysql_fetch_arr ay() is to fetch
              both numeric and associative indicies. It may just be a little slower
              Thank you.

              --
              iTech Consulting Services Limited
              Expert of ePOS solutions
              Website: http://www.itech.com.hk (IE only)
              Tel: (852)2325 3883 Fax: (852)2325 8288

              Comment

              Working...