Warning: Undefined array key in php for unknown reason

Sarai

Hello everyone
I was practicing php arrays and my editor cannot detect an error I have with my php however when it runs I get the error message

Warning: Undefined array key 3 in php

while still printing the output correctly.
my html form is:


    <!DOCTYPE html>
    <html>
        <head><title>Number of Students</title></head>
        <body>
            <form action="Q4.php">
                <table>
                    <tr>
                        <td>Number of Students:</td>
                        <td><input type="text" name="num" size="5"></td>
                        <td><input type="submit" value="Submit"></td>
                    </tr>
                </table>
            </form>
        </body>
    </html>

my php form is:


    <!DOCTYPE html>
    <html>
        <head><title>Number of Students</title></head>
        <body>
            <form action="Q4index.php">
            <table border=1 cellspacing=0 cellpadding=3>
                <tr><th>Student</th><th>Mark</th></tr>
            <?php
            $num = $_GET["num"];
            for($i=1; $i<=$num; $i++){
            echo"<tr><td><input type=text name=stud[] size=7></td>
            <td><input type=text name=mark[] size=5></td></tr>";
            }
            ?>
            <tr><td><input type="submit" value="Submit"></td><td><input type="Reset" value="Reset"</td></tr>
            </table>
            </form>
        </body>
    </html>

and the php program file to run it all is:


    <!DOCTYPE html>
    <html>
        <head><title></title></head>
        <body>
            <h3>The students who passed the exam:</h3>
            <table border="1" cellspacing="0" cellpadding="3">
                <tr><th>Name</th><th>Total Mark</th></tr>
            <?php
            //Declaration of Arrays
            $name=$_GET["stud"];
            $mark=$_GET["mark"];
            //Loop and Conditions
            for($i=0; $i<=count($name); $i++){ 
                if($mark[$i]>=50){
            //Printing        
                echo"<tr><td>$name[$i]</td><td>$mark[$i]</td></tr>";}
            }
            ?>
            </table>
        </body>
    </html>

After entering sample data in the forms and trying to execute the code this error message appears: Screenshot of error
Can someone please tell me what my code is missing? Thank you in advance and I'm beyond grateful for your patience with my questions :)

JC Cavalca

Remove '=' in condition "$i<=count($name)". Write "$i < count($name)".

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Warning: Undefined array key "submit" in php 8

error Warning: Undefined array key "name" #php

Beginner php "Warning: Undefined array key"

Warning: Undefined array key error in PHP

Warning: Undefined array key

PHP: Unable to resolve Warning: Undefined array key 0

Warning: Undefined array key 63 php8

"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP

Undefined Array Key in PHP

Find unknown array key in php?

wordpress siite: Warning: Undefined array key "scheme"

Little problem with HTML form and input tags and with PHP get method (Warning: Undefined array key)

Warning: Undefined array key "id" in D:\XAMPP\htdocs\iceico\CURD\index.php on line 20

Define undefined array key in php

PHP Illegal array key type warning (PHPStorm)

Find the value of a key in an unknown multilevel array in PHP

Undefined array key in nested array loop php

Undefined array key - image upload php

PHP gives notice undefined index on key in array

Javascript & PHP ajax error: "Undefined array key"

PHP & AJAX form "Undefined array key" error

Php key is undefined, but there is key

Angular Provider UseFactory Injecting Array for Unknown Reason

PHP View files deleted with unknown reason

PHP INSERT is not working for some unknown reason

php: mysqli login script failing for unknown reason

How do I fix an 'Undefined array key' warning in a custom post type

PHP CRUD Loading blank page or shows error undefined array key

PHP Warning: Unknown: Input variables exceeded 1000

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  3. 3

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  4. 4

    pump.io port in URL

  5. 5

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    Do Idle Snowflake Connections Use Cloud Services Credits?

  9. 9

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  10. 10

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  11. 11

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  12. 12

    Generate random UUIDv4 with Elm

  13. 13

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  14. 14

    Is it possible to Redo commits removed by GitHub Desktop's Undo on a Mac?

  15. 15

    flutter: dropdown item programmatically unselect problem

  16. 16

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  17. 17

    EXCEL: Find sum of values in one column with criteria from other column

  18. 18

    Pandas - check if dataframe has negative value in any column

  19. 19

    How to use merge windows unallocated space into Ubuntu using GParted?

  20. 20

    Make a B+ Tree concurrent thread safe

  21. 21

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

HotTag

Archive