Spikes Posted November 10, 2014 Share Posted November 10, 2014 Hi all, Having an issue with some of my php code. The goal is to have two drop-down menus, one that pulls from "ahevents_scenarios". The second pulls the "sides" involved, however it does not go into dropdown. The other issue is that even though there are only 3 sides specified, all 5 show up on the webpage. This is in Joomla. Here is my code...I think I've looked over this way too much and just can't find my errors anymore. <?php if (! $my->id) { // shouldn't even get here since menu is viewable only through logged in status print "<b>Sorry, you must be registered and logged into this site to continue</b>\n"; } else { // include standard functions and db info require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/admin_functions.php"); require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/db_admin_functions.php"); // which scenario we doing? -- replace with table lookup in future opendb('ahevents_scenarios'); if(!isset($_POST['action'])) { // display form $sqlstr2 = "select id, name from scenarios order by name"; $result2 = mysql_query($sqlstr2) or die("Error: ".mysql_error()."<br>Query: $sqlstr2"); // display form ?> <form name="edit_reg" method="post" action="<? echo $_SERVER[ 'REQUEST_URI' ]; ?>" <table> <tr> <td>Select Scenario: </td> <td> <select name="id"> <? while ( $row = mysql_fetch_array($result2)) { printf("<option value=\"%s\">%s</option>\n",$row['id'], $row['name']); } ?> </td></tr> <tr> <td>Which Side?</td> <td><select name="side"> <option value="side_1">side_1</option> <option value="side_2" >side_2</option> <option value="side_3" >side_3</option> <option value="all" selected>All</option> </select> </td></tr> </table> <p> <input type="submit" name="action" value="Get Registrants"> <input type="reset" value="Reset"> <input type="button" name="" value="Back" onClick="history.back()"> </form> The goal is to download the registrants into a .csv file, which it does, however due to not being able to select a "side", the .csv is blank with only headers, no content. Thanks for your time Rob Quote Link to comment https://forums.phpfreaks.com/topic/292388-half-of-my-code-works/ Share on other sites More sharing options...
ginerjm Posted November 10, 2014 Share Posted November 10, 2014 I don't see any output going to a csv file. I see a form wrapped around a table that has two dropdowns in it. But I don't see what you do with that input (?) or what you do to create this csv file. Quote Link to comment https://forums.phpfreaks.com/topic/292388-half-of-my-code-works/#findComment-1496220 Share on other sites More sharing options...
Spikes Posted November 10, 2014 Author Share Posted November 10, 2014 Sorry, I snipped the code to the form end. Here is the rest of the file: <p> <!-- <p>Date format is 'YYYY-MM-DD HH:MM' with the HH:MM being optional</p>A --> <? } // end of if !isset(POST) else { // update DB and post results if (isset($_POST['id'])) { $id= str_replace("\"", "'", FormatInput($_POST['id'])) ; } if (isset($_POST['side'])) { $side= str_replace("\"", "'", FormatInput($_POST['side'])) ; if ( strcmp($side, "side_1")== 0 || strcmp($side, "side_2") == 0 || strcmp($side, "side_3") == 0 ) { $side_str = " and ahevents_scenarios.members.side = '" . $side . "'" ; } elseif ( strcmp($side,"all") == 0 ) { $side_str = "" ; } else { die("Error: invalid input") ; } $sqlstr = sprintf(" select ahevents_joom1.jos_comprofiler.cb_gameid, ahevents_joom1.jos_comprofiler.cb_bbsid, ahevents_joom1.jos_comprofiler.cb_ahmasquad, ahevents_joom1.jos_comprofiler.cb_ahseasquad, ahevents_joom1.jos_users.name, ahevents_joom1.jos_users.email, ahevents_scenarios.members.side, ahevents_scenarios.members.info from ahevents_joom1.jos_comprofiler, ahevents_joom1.jos_users, ahevents_scenarios.members where ahevents_joom1.jos_users.id = ahevents_joom1.jos_comprofiler.user_id and ahevents_joom1.jos_users.id = ahevents_scenarios.members.jid and ahevents_scenarios.members.scenario_id = '%s' %s", $id, $side_str); if (isset($_POST['sqland'])) { $sqland = str_replace("\"", "'", FormatInput($_POST['sqland'])) ; if (strcmp($sqland, "na") == 0 ) { unset($sqland) ; } } if (isset($_POST['regdate'])) { $regdate = str_replace("\"", "'", FormatInput($_POST['regdate'])) ; if (isset($sqland)) { $sqlstr .= " and ( registration.reg_date >= '" . $regdate . "' " ; } else { # do nothing } } if (isset($_POST['moddate'])) { $moddate = str_replace("\"", "'", FormatInput($_POST['moddate'])) ; if (isset($sqland)) { $sqlstr .= " " . $sqland . " registration.update_date >= '" . $moddate . "') " ; } else { # do nothing } } $result = mysql_query($sqlstr) or die("Error: ".mysql_error()."<br>Query: $sqlstr"); $output = "\015\012"; $output .= "side,name,email,gameid,bbsid,ma_squad,sea_squad,info\015\012"; while ( $row = mysql_fetch_array($result)) { $output .= '"'.$row['side'].'",' ; $output .= '"'.$row['name'].'",' ; $output .= '"'.$row['email'].'",' ; $output .= '"'.$row['cb_gameid'].'",' ; $output .= '"'.$row['cb_bbsid'].'",' ; $output .= '"'.$row['cb_ahmasquad'].'",' ; $output .= '"'.$row['cb_ahseasquad'].'",' ; $output .= '"'.$row['info'].'",' ; $output .= "\015\012"; } header("Content-type: application/vnd.ms-excel"); header("Content-disposition: attachment; filename=" . $side . "_" . date("Y-m-d") . ".csv"); print $output ; exit ; print "here<br>\n" ; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/292388-half-of-my-code-works/#findComment-1496223 Share on other sites More sharing options...
Barand Posted November 10, 2014 Share Posted November 10, 2014 It looks like you are trying to nest the "selects". I don't see "</select>" after the first set of options and before the next <select> Quote Link to comment https://forums.phpfreaks.com/topic/292388-half-of-my-code-works/#findComment-1496247 Share on other sites More sharing options...
Spikes Posted November 11, 2014 Author Share Posted November 11, 2014 God I feel like a moron...thank you very much. Is there any sort of online code checker that finds these errors? I had an error reporter in the file but it did not seem to pick up on this. Quote Link to comment https://forums.phpfreaks.com/topic/292388-half-of-my-code-works/#findComment-1496301 Share on other sites More sharing options...
QuickOldCar Posted November 11, 2014 Share Posted November 11, 2014 Is there any sort of online code checker that finds these errors? http://validator.w3.org/#validate_by_input Quote Link to comment https://forums.phpfreaks.com/topic/292388-half-of-my-code-works/#findComment-1496303 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.