Jump to content

Half of my code works


Spikes

Recommended Posts

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.

 

2v9yxed.png

 

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

Link to comment
Share on other sites

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" ;
}
}
}
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.