Xtremer360 Posted June 19, 2010 Share Posted June 19, 2010 So every time I'm on option 1 the add division form and submit it then it comes up with the message "Notice: Undefined index: option in C:\wamp\www\My Backstage\backstage_libs\division.php on line 13" Why is that? <?php $e = <<<here <script src="./jscripts/scriptaculous/prototype.js" type="text/javascript"></script> <script src="./jscripts/scriptaculous/scriptaculous.js" type="text/javascript"></script> <script type="text/javascript" src="./jscripts/ajax.js"></script> here; switch ($_REQUEST['option']) { case 0: echo $e; ?> <h1 class="backstage">Division Management</h1><br /> <h2 class=backstage>Divisions :: <a href="#" onclick="ajaxpage('backstage_libs/division.php?option=1', 'content'); return false;">Add New</a></h2><br /> <?php $query = "SELECT * FROM efed_list_divisions"; $result = mysql_query ( $query ); $rows = mysql_num_rows($result); if ($rows > 0) { print '<table width="100%" class="table1"> <tr class="rowheading"> <td> </td> <td>Name</td> </tr>'; $i = 0; while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) { $sClass = 'row2'; if ($i++ % 2) $sClass = 'row1'; printf ( "<tr class=\"%s\">", $sClass ); print "<td valign=\"top\" align=center width=35><a href=\"#\" onclick=\"ajaxpage('backstage_libs/division.php?option=2&id=$row[id].', 'content'); return false;\">Edit</a></td>"; printf ( "<td valign=\"top\">%s</td>", $row ['name'] ); echo '</tr>'; } echo '</table><br>'; } else { echo '<span>There are no divisions.</span><br /><br />'; } returnmain(); footercode(); break; case 1: echo $e; require_once('../backstagefunctions.php'); ?> <h1 class="backstage">Division Management</h1><br /> <h2 class="backstage">Add New Division</h2><br /> <form name="divisions" method="post"> <input type="hidden" name="action" value="division" /> <table width="100%" class="table2"> <tr> <td width="120" class="rowheading" valign="center">Division Name:</td><td class="row3"><input type="text" name="name" class="fieldtext490"></td> </tr> </table><br /> <input type="hidden" name="newadded" value="true"> <input type="submit" value="Save Division" class="button"></form><br /> <form method="post"><input type="submit" value="Return to Division List" class="button200" name="return"> </form><br /> <?php returnmain(); break; case 2: echo $e; require_once('../backstagefunctions.php'); require_once('../backstageconfig.php'); $id = $_GET['id']; $query = mysql_query("SELECT * FROM `efed_list_divisions` WHERE `id` = '" . $id . "'"); $row = mysql_fetch_array($query); ?> <h1 class="backstage">Division Management</h1><br /> <h2 class="backstage">Edit Division</h2><br /> <form name="editdivision" method="post"> <input type="hidden" name="action" value="division" /> <table width="100%" class="table2"> <tr> <td width="120" class="rowheading" valign="center">Division:</td><td class="row3"><input type="text" name="name" class="fieldtext490" value="<?=$row['name'];?>"></td> </tr> </table><br /> <center> <input type="checkbox" name="deletename"><span class="table1heading">Delete Division?</span><br /><br /> <input type="hidden" name="oldname" value="<?php echo $row['name']; ?>"> <input type="hidden" value="true" name="editted" /> <input type="submit" value="Edit Division" class="button"><br /><br /> <input type="button" value="Return to Divisions List" class="button200"><br /><br /> </form> <?php returnmain(); break; } function division() { $name = mysql_real_escape_string($_POST['name']); if ((!empty($_POST['newadded']))) { $name = mysql_real_escape_string($_POST['name']); $query = "INSERT INTO `efed_list_divisions` (name) VALUES ('".$name."')"; mysql_query($query); } if ((!empty($_POST['editted']))) { $oldname = mysql_real_escape_string($_POST['oldname']); $query = "UPDATE `efed_list_divisions` SET `name` = '$name' WHERE `name` = '$oldname'"; mysql_query($query); if (isset($_POST['deletename'])){ $query = "DELETE FROM `efed_list_divisions` WHERE `name` = '".$name."' LIMIT 1"; mysql_query($query); } } } ?> Link to comment https://forums.phpfreaks.com/topic/205229-undefined-index/ Share on other sites More sharing options...
trq Posted June 19, 2010 Share Posted June 19, 2010 Because $_REQUEST['option'] isn't defined at the time. Your entire switch should be in between a check for its existence. if (isset($_REQUEST['option'])) { switch ($_REQUEST['option']) { // rest of code } } Link to comment https://forums.phpfreaks.com/topic/205229-undefined-index/#findComment-1074238 Share on other sites More sharing options...
Xtremer360 Posted June 19, 2010 Author Share Posted June 19, 2010 Cool. Works great now however after submission it goes to a white screen. I have it set to go back to list of divisions aka option 1 but it doesn't. Know why that is? Link to comment https://forums.phpfreaks.com/topic/205229-undefined-index/#findComment-1074239 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.