Magestickown Posted February 7, 2010 Share Posted February 7, 2010 Please help me, I keep getting undefined index Here's my code: <?php ////////////////// if ($_GET['formradio1']=='') <--- Line 179 { ?> <html> <div id="image1" style="position:absolute; overflow:hidden; left:0px; top:495px; width:658px; height:500px; z-index:0"><img src="images/default.jpg" alt="" title="" border=0 width=658 height=500></div> <left> </html> <?php } if ($_GET['formradio1']=='HTR') <----- Line 190 { ?> <html> <div id="image2" style="position:absolute; overflow:hidden; left:0px; top:495px; width:658px; height:500px; z-index:1"><img src="images/htr.jpg" alt="" title="" border=0 width=658 height=500></div> <left> </html> <?php } /////////////////////////// if ($_GET['formradio1']=='faq') <------ Line 202 { ?> <html> <div id="image2" style="position:absolute; overflow:hidden; left:0px; top:495px; width:658px; height:500px; z-index:1"><img src="images/faq.jpg" alt="" title="" border=0 width=658 height=500></div> <left> </html> <?php } /////////////////////////// if ($_GET['formradio1']=='bridge') <------ Line 214 { ?> <html> <div id="image2" style="position:absolute; overflow:hidden; left:0px; top:495px; width:658px; height:500px; z-index:1"><img src="images/bridge.jpg" alt="" title="" border=0 width=658 height=500></div> <left> </html> <?php } ////////// ?> And my error: Notice: Undefined index: formradio1 in C:\wamp\www\help.php on line 179 Notice: Undefined index: formradio1 in C:\wamp\www\help.php on line 190 Notice: Undefined index: formradio1 in C:\wamp\www\help.php on line 202 Notice: Undefined index: formradio1 in C:\wamp\www\help.php on line 214 The name of my radio button is fromradio1 - How would I make it a defined index to load the image? Quote Link to comment https://forums.phpfreaks.com/topic/191227-undefined-index/ Share on other sites More sharing options...
Daniel0 Posted February 7, 2010 Share Posted February 7, 2010 Radio buttons and check boxes will only be submitted by the browser if they're checked. Use isset or array_key_exists to check if the index exists. Also, use an else if for the other conditions because they're all mutually exclusive. Quote Link to comment https://forums.phpfreaks.com/topic/191227-undefined-index/#findComment-1008276 Share on other sites More sharing options...
Magestickown Posted February 7, 2010 Author Share Posted February 7, 2010 Radio buttons and check boxes will only be submitted by the browser if they're checked. Use isset or array_key_exists to check if the index exists. Can you explain that a bit more? I'm very new to PHP Quote Link to comment https://forums.phpfreaks.com/topic/191227-undefined-index/#findComment-1008278 Share on other sites More sharing options...
Daniel0 Posted February 7, 2010 Share Posted February 7, 2010 if (empty($_GET['formradio1'])) { // ... } else if ($_GET['formradio1'] == 'foo') { // ... } else if ($_GET['formradio1'] == 'bar') { // ... } // ... else { // something else // ... } Or using a switch: if (empty($_GET['formradio1'])) { // ... } else { switch($_GET['formradio1']) { case 'foo': // ... break; case 'bar': // ... break; default: // ... break; } } Quote Link to comment https://forums.phpfreaks.com/topic/191227-undefined-index/#findComment-1008279 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.