KevinM1 Posted July 3, 2007 Share Posted July 3, 2007 This is, of course, related to my PHP-Fusion modifications. I have a script called registration_viewer. It's pretty simple. It generates a pull-down list of the events people registered for. There's a difference in the form if someone is a site administrator or just a normal member, but it's nothing too complicated and works fine. When someone selects an event they registered for (or all of their registered events), the info is passed along to registration_controller where they can edit or delete registrations. My problem is with this second script, specifically when I'm logged in as an administrator. My problem is that the two pulldown lists are interefering with one another. More precisely, no matter what one selects with the bottom list, the value selected in the top list will be the one the administrator gets. I've tried everything I could think of to this point to separate the lists' behaviors, but nothing has worked. Please help. Code is below. registration_viewer.php: <?php /* This will be the file that will allow Rebecca to view/edit event information. Right now, it's pseudo-code. All users should have the ability to view, edit, and delete their registrations (WHERE: ev_id, user_id). VIEW: all/select date (* / WHERE ev_start) EDIT: only one at a time (redirect to registration form, pass info by GET). DELETE: multiple (see store on how to do it). */ require_once "maincore.php"; require_once "subheader.php"; require_once "side_left.php"; /* ADMIN should have the ability to view and delete ALL registrations. ADMIN VIEW: all/select date (* / WHERE ev_start). ADMIN DELETE: multiple (see store on how to do it). */ if(iADMIN){ // Form uses separate script for its action. // Construct personal pulldown from user_id and login_timestamp. // Construct admin pulldown from * and ev_start. // 'Go' submit button for both. $personalQuery = "SELECT * FROM ". DB_PREFIX ."aflac WHERE user_id = '". $userdata['user_id'] ."'"; $personalResult = dbquery($personalQuery); $adminQuery = "SELECT * FROM ". DB_PREFIX ."aflac"; $adminResult = dbquery($adminQuery); echo "<form method='post' action='registration_controller.php'>\n<br />\n"; echo "Your registrations: <br /><br />\n"; echo "<select name='personalEvents[]'>\n<br />\n"; echo "<option value=''>--</option>\n<br />\n"; echo "<option value='*'>All</option>\n<br />\n"; while($row = mysql_fetch_assoc($personalResult)){ echo "<option value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}'>{$row['ev_title']} -- ". date('M j, Y', $row['login_timestamp']) ."</option>\n<br />\n"; } echo "</select>\n"; echo "<input type='submit' name='personalSubmit' value='Go' />\n<br />\n<br /><br /><br /><br />\n"; echo "All registrations: <br /><br />\n"; echo "<select name='adminEvents[]'>\n<br />\n"; echo "<option value=''>--</option>\n<br />\n"; echo "<option value='*'>All</option>\n<br />\n"; while($row = mysql_fetch_assoc($adminResult)){ echo "<option value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}'>{$row['registering_agent']}: {$row['ev_title']} -- ". date('M j, Y', $row['login_timestamp']) ."</option>\n<br />\n"; } echo "</select>\n"; echo "<input type='submit' name='adminSubmit' value='Go' />\n<br />\n<br />\n</form>\n"; } /* while(getrow){ //separate script Put checkbox next to each row for deletion. } See store on how to match up arrays (remember their keys). } */ if(iMEMBER && !iADMIN){ // Form uses separate script for its action. // Construct pulldown from user_id and login_timestamp. // 'Go' submit button. $query = "SELECT * FROM ". DB_PREFIX ."aflac WHERE user_id = '". $userdata['user_id'] ."'"; $result = dbquery($query); echo "<form method='post' action='registration_controller.php'>\n<br />\n"; echo "<select name='events[]'>\n<br />\n"; echo "<option value=''>--</option>\n<br />\n"; echo "<option value='*'>All</option>\n<br />\n"; while($row = mysql_fetch_assoc($result)){ //check Fusion db stuff echo "<option value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}'>{$row['ev_title']} -- ". date('M j, Y', $row['login_timestamp']) ."</option>\n<br />\n"; } echo "</select>\n"; echo "<input type='submit' name='submit' value='Go' />\n<br />\n</form>\n<br />\n"; } /* while(getrow){ //separate script Put checkbox next to each row for deletion. } TWO BUTTONS: 'Edit' (brings the first registration info back to the registration form) and 'Delete' (deletes all checked rows). } */ require_once "side_right.php"; require_once "footer.php"; ?> registration_controller.php (where the problem lies as it handles what registration_viewer.php sends): <?php require_once "maincore.php"; require_once "subheader.php"; require_once "side_left.php"; if(!iMEMBER){ fallback(); } if(isset($_POST['edit'])){ if(isset($_POST['events'])){ $event = explode(", ", $_POST['events'][0]); $user_id = $event[0]; $ev_id = $event[1]; $login_timestamp = $event[2]; $query = "SELECT * FROM ". DB_PREFIX ."aflac WHERE user_id = '$user_id' AND ev_id = '$ev_id' AND login_timestamp = '$login_timestamp'"; $result = dbquery($query); $row = mysql_fetch_assoc($result); // echo "Event ID: {$row['ev_id']}, Registering Agent: {$row['registering_agent']}, Agent Writing Number: {$row['agent_writing_number']}, Phone: {$row['phone']}, E-mail: {$row['email']}, Regional Sales Coordinator: {$row['regional_sales_coordinator']}, District Sales Coordinator: {$row['district_sales_coordinator']}<br /><br />"; header("Location: ". BASEDIR ."registration.php?evid={$row['ev_id']}®Agent={$row['registering_agent']}&agentWritingNum={$row['agent_writing_number']}&phone={$row['phone']}&email={$row['email']}®Sales={$row['regional_sales_coordinator']}&disSales={$row['district_sales_coordinator']}"); } } if(isset($_POST['personalEvents']) && (!isset($_POST['adminEvents']) || isset($_POST['adminEvents']))){ if($_POST['personalEvents'][0] == '*'){ $personalQuery = "SELECT * FROM ". DB_PREFIX ."aflac WHERE user_id = '". $userdata['user_id'] ."'"; echo $personalQuery ."<br /><br />"; $personalResult = dbquery($personalQuery); echo "<form method='post' action='{$_SERVER['PHP_SELF']}'>\n"; echo "<table cellspacing='0'>\n\t<tr>\n\t\t<th></th><th>Registering Agent</th><th>Agent Writing Number</th><th>Phone Number</th><th>E-mail Address</th><th>Regional Sales Coordinator</th><th>District Sales Coordinator</th>\n\t</tr>"; $count = 0; while($row = mysql_fetch_assoc($personalResult)){ if($count % 2 == 0){ echo "\n\t<tr class='regtbl1'>\n\t\t<td><input type='checkbox' name='personalEvents[]' value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}' /></td><td>{$row['registering_agent']}</td><td>{$row['agent_writing_number']}</td><td>{$row['phone']}</td><td>{$row['email']}</td><td>{$row['regional_sales_coordinator']}</td><td>{$row['district_sales_coordinator']}</td>\n\t</tr>"; } else{ echo "\n\t<tr class='regtbl2'>\n\t\t<td><input type='checkbox' name='personalEvents[]' value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}' /></td><td>{$row['registering_agent']}</td><td>{$row['agent_writing_number']}</td><td>{$row['phone']}</td><td>{$row['email']}</td><td>{$row['regional_sales_coordinator']}</td><td>{$row['district_sales_coordinator']}</td>\n\t</tr>"; } $count++; } echo "</table>\n<input type='submit' name='edit' value='Edit' /><input type='submit' name='delete' value='Delete' />\n</form>"; } else if($_POST['personalEvents'][0] != ''){ $event = explode(", ", $_POST['personalEvents'][0]); $user_id = $event[0]; $ev_id = $event[1]; $login_timestamp = $event[2]; $personalQuery = "SELECT * FROM ". DB_PREFIX ."aflac WHERE user_id = '$user_id' AND ev_id = '$ev_id' AND login_timestamp = '$login_timestamp'"; echo $personalQuery ."<br /><br />"; $personalResult = dbquery($personalQuery); echo "<form method='post' action='{$_SERVER['PHP_SELF']}'>\n"; echo "<table cellspacing='0'>\n\t<tr>\n\t\t<th></th><th>Registering Agent</th><th>Agent Writing Number</th><th>Phone Number</th><th>E-mail Address</th><th>Regional Sales Coordinator</th><th>District Sales Coordinator</th>\n\t</tr>"; while($row = mysql_fetch_assoc($personalResult)){ echo "\n\t<tr class='regtbl1'>\n\t\t<td><input type='checkbox' name='personalEvents[]' value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}' /></td><td>{$row['registering_agent']}</td><td>{$row['agent_writing_number']}</td><td>{$row['phone']}</td><td>{$row['email']}</td><td>{$row['regional_sales_coordinator']}</td><td>{$row['district_sales_coordinator']}</td>\n\t</tr>"; } echo "</table>\n<input type='submit' name='edit' value='Edit' /><input type='submit' name='delete' value='Delete' />\n</form>"; } } else if(isset($_POST['events'])){ if($_POST['events'][0] == '*'){ $personalQuery = "SELECT * FROM ". DB_PREFIX ."aflac WHERE user_id = '". $userdata['user_id'] ."'"; echo $personalQuery ."<br /><br />"; $personalResult = dbquery($personalQuery); echo "<form method='post' action='{$_SERVER['PHP_SELF']}'>\n"; echo "<table cellspacing='0'>\n\t<tr>\n\t\t<th></th><th>Registering Agent</th><th>Agent Writing Number</th><th>Phone Number</th><th>E-mail Address</th><th>Regional Sales Coordinator</th><th>District Sales Coordinator</th>\n\t</tr>"; $count = 0; while($row = mysql_fetch_assoc($personalResult)){ if($count % 2 == 0){ echo "\n\t<tr class='regtbl1'>\n\t\t<td><input type='checkbox' name='events[]' value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}' /></td><td>{$row['registering_agent']}</td><td>{$row['agent_writing_number']}</td><td>{$row['phone']}</td><td>{$row['email']}</td><td>{$row['regional_sales_coordinator']}</td><td>{$row['district_sales_coordinator']}</td>\n\t</tr>"; } else{ echo "\n\t<tr class='regtbl2'>\n\t\t<td><input type='checkbox' name='events[]' value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}' /></td><td>{$row['registering_agent']}</td><td>{$row['agent_writing_number']}</td><td>{$row['phone']}</td><td>{$row['email']}</td><td>{$row['regional_sales_coordinator']}</td><td>{$row['district_sales_coordinator']}</td>\n\t</tr>"; } $count++; } echo "</table>\n<input type='submit' name='edit' value='Edit' /><input type='submit' name='delete' value='Delete' />\n</form>"; } else if($_POST['events'][0] != ''){ $event = explode(", ", $_POST['events'][0]); $user_id = $event[0]; $ev_id = $event[1]; $login_timestamp = $event[2]; $personalQuery = "SELECT * FROM ". DB_PREFIX ."aflac WHERE user_id = '$user_id' AND ev_id = '$ev_id' AND login_timestamp = '$login_timestamp'"; echo $personalQuery ."<br /><br />"; $personalResult = dbquery($personalQuery); echo "<form method='post' action='{$_SERVER['PHP_SELF']}'>\n"; echo "<table cellspacing='0'>\n\t<tr>\n\t\t<th></th><th>Registering Agent</th><th>Agent Writing Number</th><th>Phone Number</th><th>E-mail Address</th><th>Regional Sales Coordinator</th><th>District Sales Coordinator</th>\n\t</tr>"; while($row = mysql_fetch_assoc($personalResult)){ echo "\n\t<tr class='regtbl1'>\n\t\t<td><input type='checkbox' name='events[]' value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}' /></td><td>{$row['registering_agent']}</td><td>{$row['agent_writing_number']}</td><td>{$row['phone']}</td><td>{$row['email']}</td><td>{$row['regional_sales_coordinator']}</td><td>{$row['district_sales_coordinator']}</td>\n\t</tr>"; } echo "</table>\n<input type='submit' name='edit' value='Edit' /><input type='submit' name='delete' value='Delete' />\n</form>"; } } else if(isset($_POST['adminEvents']) && (!isset($_POST['personalEvents']) || isset($_POST['personalEvents']))){ if($_POST['adminEvents'][0] == '*'){ $adminQuery = "SELECT * FROM ". DB_PREFIX ."aflac"; echo $adminQuery ."<br /><br />"; $adminResult = dbquery($adminQuery); echo "<form method='post' action='{$_SERVER['PHP_SELF']}'>\n"; echo "<table cellspacing='0'>\n\t<tr>\n\t\t<th></th><th>Registering Agent</th><th>Agent Writing Number</th><th>Phone Number</th><th>E-mail Address</th><th>Regional Sales Coordinator</th><th>District Sales Coordinator</th>\n\t</tr>"; $count = 0; while($row = mysql_fetch_assoc($adminResult)){ if($count % 2 == 0){ echo "\n\t<tr class='regtbl1'>\n\t\t<td><input type='checkbox' name='adminEvents[]' value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}' /></td><td>{$row['registering_agent']}</td><td>{$row['agent_writing_number']}</td><td>{$row['phone']}</td><td>{$row['email']}</td><td>{$row['regional_sales_coordinator']}</td><td>{$row['district_sales_coordinator']}</td>\n\t</tr>"; } else{ echo "\n\t<tr class='regtbl2'>\n\t\t<td><input type='checkbox' name='adminEvents[]' value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}' /></td><td>{$row['registering_agent']}</td><td>{$row['agent_writing_number']}</td><td>{$row['phone']}</td><td>{$row['email']}</td><td>{$row['regional_sales_coordinator']}</td><td>{$row['district_sales_coordinator']}</td>\n\t</tr>"; } $count++; } echo "</table>\n<input type='submit' name='delete' value='Delete' />\n</form>"; } else if($_POST['adminEvents'][0] != ''){ $event = explode(", ", $_POST['adminEvents'][0]); $user_id = $event[0]; $ev_id = $event[1]; $login_timestamp = $event[2]; $adminQuery = "SELECT * FROM ". DB_PREFIX ."aflac WHERE ev_id = '$ev_id' AND login_timestamp = '$login_timestamp'"; echo $adminQuery ."<br /><br />"; $adminResult = dbquery($adminQuery); echo "<form method='post' action='{$_SERVER['PHP_SELF']}'>\n"; echo "<table cellspacing='0'>\n\t<tr>\n\t\t<th></th><th>Registering Agent</th><th>Agent Writing Number</th><th>Phone Number</th><th>E-mail Address</th><th>Regional Sales Coordinator</th><th>District Sales Coordinator</th>\n\t</tr>"; while($row = mysql_fetch_assoc($adminResult)){ echo "\n\t<tr class='regtbl1'>\n\t\t<td><input type='checkbox' name='adminEvents[]' value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}' /></td><td>{$row['registering_agent']}</td><td>{$row['agent_writing_number']}</td><td>{$row['phone']}</td><td>{$row['email']}</td><td>{$row['regional_sales_coordinator']}</td><td>{$row['district_sales_coordinator']}</td>\n\t</tr>"; } echo "</table>\n<input type='submit' name='delete' value='Delete' />\n</form>"; } } require_once "side_right.php"; require_once "footer.php"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/58249-solved-please-help-with-logic-error/ Share on other sites More sharing options...
Wildbug Posted July 3, 2007 Share Posted July 3, 2007 You're only getting personalEvents because you have adminEvents in an elseif in the same if block. Change the elseif to an if. Also, why do you do this? if(isset($_POST['adminEvents']) && (!isset($_POST['personalEvents']) || isset($_POST['personalEvents']))){ "If it is or it isn't set?" Same as: if(isset($_POST['adminEvents'])) { Quote Link to comment https://forums.phpfreaks.com/topic/58249-solved-please-help-with-logic-error/#findComment-288798 Share on other sites More sharing options...
KevinM1 Posted July 3, 2007 Author Share Posted July 3, 2007 You're only getting personalEvents because you have adminEvents in an elseif in the same if block. Change the elseif to an if. Also, why do you do this? if(isset($_POST['adminEvents']) && (!isset($_POST['personalEvents']) || isset($_POST['personalEvents']))){ "If it is or it isn't set?" Same as: if(isset($_POST['adminEvents'])) { Heh, that's what I get for coding at 7:30 AM. Removing the elseif's almost works perfectly. The only problem is that both the personal event table and admin event table show up if there are events selected in each list... actually, now that I think about it, I should give each submit button on the viewer a different name. That would probably take care of everything. And yes, I'm 'talking' to myself. Quote Link to comment https://forums.phpfreaks.com/topic/58249-solved-please-help-with-logic-error/#findComment-288863 Share on other sites More sharing options...
KevinM1 Posted July 3, 2007 Author Share Posted July 3, 2007 Turns out I already named my submit buttons in the viewer script... d'oh! It's all solved now. Quote Link to comment https://forums.phpfreaks.com/topic/58249-solved-please-help-with-logic-error/#findComment-288897 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.