metroman90210 Posted May 10, 2021 Share Posted May 10, 2021 I have been using an application that was working fine using php 5.6.39 but I have to update my version of php to 7.x and am trying to fix the issues relating to that conversion. I am currently running into this error message: Notice: Undefined index: sqNum_00 in C:\usbwebserver865\root\superbowlLV\signup.php on line 23 The block of code that this refers to is as follows: if ( isset($_REQUEST['sqSelect_Submit']) ) { $SQ=0; $SQcount = 100; for ($i=0;$i<$SQcount;$i++) { if ($i<10) { $SQarray[$i] = $_POST["sqNum_0$i"]; } //This is line 23 referenced in the error message else { $SQarray[$i] = $_POST["sqNum_$i"]; } if ( isset($SQarray[$i]) ) { $SQ++; echo $SQarray[$i]." "; echo ('<input type="hidden" name="square_'.$SQ.'" value="'.$SQarray[$i].'">'); echo ('<input type="hidden" name="sqTotal" value="'.$SQ.'">'); if ( $SQ == 10 ) { echo "<p>Maximum of 10 Squares per selection</p>"; break; } // limit to 10 } } Any assistance provided would be greatly appreciated. BTW, this error message is repeated for the 100 squares in the grid such as sqNum_01 etc. although it always refers to the same line number. Quote Link to comment https://forums.phpfreaks.com/topic/312660-notice-undefined-index-issue/ Share on other sites More sharing options...
Barand Posted May 10, 2021 Share Posted May 10, 2021 (edited) What does your POST array actually contain? Put this before the for() loop. echo '<pre>' . print_r($_POST, 1) . '</pre>'; Edited May 10, 2021 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/312660-notice-undefined-index-issue/#findComment-1586449 Share on other sites More sharing options...
mac_gyver Posted May 10, 2021 Share Posted May 10, 2021 the code is blindly looping over 100 possible values, without testing if they exist before referencing them. this error was always occurring, but was probably not being reported or displayed. you should use an array for the form field, with the array index being the 0-99 value. this will eliminate the need for the logic to take the $_POST[sqNum_xx] value and put it into $SQarray[xx]. you will already have an array of data from the form that the if ( isset($SQarray[$i]) ) { can test and use. Quote Link to comment https://forums.phpfreaks.com/topic/312660-notice-undefined-index-issue/#findComment-1586450 Share on other sites More sharing options...
metroman90210 Posted May 10, 2021 Author Share Posted May 10, 2021 Thank you both (Barand and mac_gyver) for your responses. This is not coding I have developed...the developer has gone off the grid so I am trying to "fix" the myriad of problems with the code by googling the error messages as they come up. Barand...I assume that the code you asked me to enter was to determine what the POST array contained and if that is the case, this is what was echoed after I selected square # 64 Array ( [sqNum_64] => 64 [sqSelect_Submit] => Submit ) mac_byver...I wouldn't know how to use an array...sorry. Quote Link to comment https://forums.phpfreaks.com/topic/312660-notice-undefined-index-issue/#findComment-1586451 Share on other sites More sharing options...
mac_gyver Posted May 10, 2021 Share Posted May 10, 2021 is this code doing anything else with the submitted values beyond building the hidden fields in the form? btw - the sqTotal field being repeatedly output is pointless. it should just be output once, after the end of the looping, and i would even venture to guess that it is not needed anyways. Quote Link to comment https://forums.phpfreaks.com/topic/312660-notice-undefined-index-issue/#findComment-1586455 Share on other sites More sharing options...
Barand Posted May 10, 2021 Share Posted May 10, 2021 1 hour ago, metroman90210 said: ...the developer has gone off the grid Probably one of his other clients caught up with him 1 hour ago, metroman90210 said: Array ( [sqNum_64] => 64 [sqSelect_Submit] => Submit ) In which case, sqNum_64 is the only one out of the hundred that won't give you an error. Do as mac_gyver suggested and name your inputs ... name="sqNum[n]" where n is a number from 1 to 100. You can then process the input withsomething like ... foreach ($_POST['sqNum'] as $i => $val) { // process $i } Out of curiosity, what does the input form code look like and what is it supposed to do? Quote Link to comment https://forums.phpfreaks.com/topic/312660-notice-undefined-index-issue/#findComment-1586456 Share on other sites More sharing options...
metroman90210 Posted May 10, 2021 Author Share Posted May 10, 2021 Rather than trying to explain how this is supposed to work, I have set up the application on a webhost running php version 7.4.16 If you click on a square (you can click on a maximum of 10, you will see that it takes you to a page that is supposed to list the square numbers you have selected. After "fixing" some of the code, this is what that page looks like and as you can see, the square numbers are not being displayed. SuperBowl Squares Application Quote Link to comment https://forums.phpfreaks.com/topic/312660-notice-undefined-index-issue/#findComment-1586458 Share on other sites More sharing options...
Barand Posted May 10, 2021 Share Posted May 10, 2021 Oh right. It's one of those. I wrote an application like that about three years ago. If you want to display what has been selected then hidden fields don't seem the best option to me Quote Link to comment https://forums.phpfreaks.com/topic/312660-notice-undefined-index-issue/#findComment-1586461 Share on other sites More sharing options...
metroman90210 Posted May 10, 2021 Author Share Posted May 10, 2021 Is the application you wrote available either open source or paid? Quote Link to comment https://forums.phpfreaks.com/topic/312660-notice-undefined-index-issue/#findComment-1586462 Share on other sites More sharing options...
Barand Posted May 10, 2021 Share Posted May 10, 2021 It is slightly different from yours A set of selections is valid only for a selected game, whereas yours is valid for 19 games. I update the database with each selection as soon as it is clicked (recording game_id/user_id/square_id) There is no on-line monetary collection. You paid the club treasurer in cash. One problem was that no-one wanted to bet on my team's score ending (or starting) with anything other than zero, even though I remember we did score once. Quote Link to comment https://forums.phpfreaks.com/topic/312660-notice-undefined-index-issue/#findComment-1586464 Share on other sites More sharing options...
metroman90210 Posted May 10, 2021 Author Share Posted May 10, 2021 This looks exactly like mine. Mine is only good for one game...there are payouts for every score in the game and that scoring is done manually by me. All the squares must be sold before the numbers in the left hand and bottom panels are randomly generated so no player knows what numbers he will have until the grid is sold out. I collect all money before the game starts either by check, benmo or paypal. If your application is available, I would love to take a look at it assuming it is open source. If it is not open source, let me know the cost of it. I assume it would work with php versions 7.4.x? Quote Link to comment https://forums.phpfreaks.com/topic/312660-notice-undefined-index-issue/#findComment-1586465 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.