Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
Donovan
Client



Joined: Oct 07, 2003
Posts: 735
Location: Ohio

PostPosted: Wed Jun 28, 2006 8:51 pm Reply with quote

What is a better way of doing this? I want to make sure that each soldier added to the roster is assigned to a unit.

Here is my code:


Code:
if ($op == "NewSoldier") {

   
   // Validations go here.
   // All soldiers must belong to a unit before they are displayed.
   if (!is_numeric($_POST['unit_id'])) {      
   echo"<table width=\"100%\" border=\"1\" cellpadding=\"2\" align=\"center\">";
   echo"<tr>";
   echo"<td align=\"center\" bgcolor=\"$bgcolor2\"><b><font color=\"red\">All soldiers must be assigned to a unit!</font></b></td>";
   echo"</tr>";
   echo"</table>";
}else{
   $unit_id = intval($_POST['unit_id']);
   
   //Process the rest of the values
   $ismember = ($_POST['ismember']);
   $rank_id = intval($_POST['rank_id']);   
    $weapon_id = intval($_POST['weapon_id']);
    $bio = addslashes($_POST['bio']);   
   $soldierName = $_POST['u_name'];
   $nukeusername = $_POST['nukeusername'];
   $uniform = $_POST['uniform'];
   $flag = $_POST['flag'];
   $location = $_POST['location'];
   $status = $_POST['status'];
   $p_mos = $_POST['p_mos'];
   $reports = $_POST['reports'];
   $position = $_POST['position'];
   $enlistment_dt = $_POST['enlistment_dt'];      
   $icq = $_POST['icq'];      
         


If I don't assign a unit then on submit it will display a line at the top of my page with the validation,

Code:
echo"<td align=\"center\" bgcolor=\"$bgcolor2\"><b><font color=\"red\">All soldiers must be assigned to a unit!</font></b></td>";


however it also does not keep some of my textboxes filled with data that I just entered.

$soldierName = $_POST['u_name'];
$nukeusername = $_POST['nukeusername'];

are blank.

If I add a unit then everything processes normally including my ismember flag. If I have the error displayed and try to reenter the data and then assigns a unit then the ismember flag does not update with any value.

This is the last thing I need to get working flawlessly before I release RC2 of my module.

Any help is appreciaetd.
 
View user's profile Send private message Visit poster's website ICQ Number
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Wed Jun 28, 2006 9:26 pm Reply with quote

That would be because you define those variables only if unit is assigned. If you want them populated regardless, then don't make them dependent in the "else" statement.
 
View user's profile Send private message
Donovan







PostPosted: Wed Jun 28, 2006 9:35 pm Reply with quote

So move these:

Code:
$ismember = ($_POST['ismember']); 

   $rank_id = intval($_POST['rank_id']);   
    $weapon_id = intval($_POST['weapon_id']);
    $bio = addslashes($_POST['bio']);   
   $soldierName = $_POST['u_name'];
   $nukeusername = $_POST['nukeusername'];
   $uniform = $_POST['uniform'];
   $flag = $_POST['flag'];
   $location = $_POST['location'];
   $status = $_POST['status'];
   $p_mos = $_POST['p_mos'];
   $reports = $_POST['reports'];
   $position = $_POST['position'];
   $enlistment_dt = $_POST['enlistment_dt'];       
   $icq = $_POST['icq'];       


above my else statement? I tried that and it didn't work.

Was this what you mean?



Code:
if ($op == "NewSoldier") {

   
   $ismember = ($_POST['ismember']);
   $rank_id = intval($_POST['rank_id']);   
    $weapon_id = intval($_POST['weapon_id']);
    $bio = addslashes($_POST['bio']);   
   $soldierName = $_POST['u_name'];
   $nukeusername = $_POST['nukeusername'];
   $uniform = $_POST['uniform'];
   $flag = $_POST['flag'];
   $location = $_POST['location'];
   $status = $_POST['status'];
   $p_mos = $_POST['p_mos'];
   $reports = $_POST['reports'];
   $position = $_POST['position'];
   $enlistment_dt = $_POST['enlistment_dt'];      
   $icq = $_POST['icq'];

   // Validations go here.
   // All soldiers must belong to a unit before they are displayed.
   if (!is_numeric($unit_id)) {      
   echo"<table width=\"100%\" border=\"1\" cellpadding=\"2\" align=\"center\">";
   echo"<tr>";
   echo"<td align=\"center\" bgcolor=\"$bgcolor2\"><b><font color=\"red\">All soldiers must be assigned to a unit!</font></b></td>";
   echo"</tr>";
   echo"</table>";
   } else {
   $unit_id = intval($_POST['unit_id']);
 
Raven







PostPosted: Wed Jun 28, 2006 9:43 pm Reply with quote

Yes. If that doesn't work then it would seem that your form isn't set up correctly.
 
Donovan







PostPosted: Wed Jun 28, 2006 10:11 pm Reply with quote

Any ideas?

Code:
<?php

/************************************************************************/
/* MILPACS (Military Personell and Classification System)               */
/* Author::Donovan [3rd ID]                                    */
/* Copyright (c) 2005 by Steven Donovan AKA Donovan [3rd ID]         */
/* Email:: donovan@3rd-infantry-division.net
/* Homepage::http://www.3rd-infantry-division.net                  */
/*                                                      */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/*                                                                      */
/* This program is distributed in the hope that it will be useful, but  */
/* WITHOUT ANY WARRANTY; without even the implied warranty of           */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU     */
/* General Public License for more details.                             */
/*                                                                      */
/* If you want a copy of the GNU General Public License write to the    */
/* Free Software Foundation, Inc.                              */
/* 59 Temple Place, Suite 330, Boston, MA 02111-1307               */
/* USA                                                                  */
/************************************************************************/
/*********************************************************/
/* Add Soldier to MILPACS                                */
/*********************************************************/

if (!defined('ADMIN_FILE')) {
die ("Access Denied");
}

define('INDEX_FILE', true);
$index = 1;
include_once("header.php");
global $module_name, $db, $prefix, $bgcolor1, $bgcolor2;
$IMAGEPATH = $_SERVER['DOCUMENT_ROOT'];

if ($op == "NewSoldier") {
   
   $ismember = ($_POST['ismember']);
   $rank_id = intval($_POST['rank_id']);   
    $weapon_id = intval($_POST['weapon_id']);
    $bio = addslashes($_POST['bio']);   
   $soldierName = $_POST['u_name'];
   $nukeusername = $_POST['nukeusername'];
   $uniform = $_POST['uniform'];
   $flag = $_POST['flag'];
   $location = $_POST['location'];
   $status = $_POST['status'];
   $p_mos = $_POST['p_mos'];
   $reports = $_POST['reports'];
   $position = $_POST['position'];
   $enlistment_dt = $_POST['enlistment_dt'];      
   $icq = $_POST['icq'];

   // Validations go here.
   // All soldiers must belong to a unit before they are displayed.
   if (!is_numeric($unit_id)) {      
   echo"<table width=\"100%\" border=\"1\" cellpadding=\"2\" align=\"center\">";
   echo"<tr>";
   echo"<td align=\"center\" bgcolor=\"$bgcolor2\"><b><font color=\"red\">All soldiers must be assigned to a unit!</font></b></td>";
   echo"</tr>";
   echo"</table>";
   } else {
   $unit_id = intval($_POST['unit_id']);   
   
      
   //Insert the values into the correct database with the right fields
   $result = $db->sql_query ("INSERT INTO " . $prefix . "_milpacs_members (uniqueid, ismember, u_name, nukeusername, uniform, rank_id, flag, location, status, p_mos, unit_id,  reports, position, weapon_id, enlistment_dt, icq, bio)".
      "VALUES ('NULL', '$ismember', '$soldierName', '$nukeusername', '$uniform', $rank_id, '$flag', '$location', '$status', '$p_mos', $unit_id, '$reports', '$position', $weapon_id, '$enlistment_dt', '$icq', '$bio')");

   if (!$result) {
       echo("<p>Error adding Soldier!" . mysql_error() . "</p>");
   }else {
      $result = $db->sql_query($sql);
      echo "<META HTTP-EQUIV=\"refresh\" content=\"0;URL=admin.php?op=milpacs\">";
   }
}   
}         
         
// Load Uniform images (Rank, Flag)
   $urlofimages="$IMAGEPATH/modules/MILPACS/images/uniform/";
   $uniformselecthtml = "<select name=\"uniform\">";
   $uniformselecthtml .= "<option value=\"\">Select Uniform Image</option>";
   if ($handle=@opendir($urlofimages)) {
      while ($imgfile = readdir($handle)) {
         if ($imgfile != "." && $imgfile != ".." && $imgfile != "" && $imgfile != "index.html" && $imgfile != "WS_FTP.LOG" && $imgfile != "Thumbs.db") {
//          echo "$imgfile<br>";
            if ($imgfile==$uniform) {
               $uniformselecthtml .= "<option value =\"$imgfile\" selected>$imgfile</option>";
            } else {
               $uniformselecthtml .= "<option value =\"$imgfile\" >$imgfile</option>";
            }
         }
      }
      @closedir($handle);
   }
   $uniformselecthtml .= "</select></td>";

// Load Ranks
   $rankselecthtml = "<select name=\"rank_id\">";
   $rankselecthtml .= "<option value=\"\">Select Rank</option>";
    $result2 = $db->sql_query("SELECT * FROM " . $prefix . "_milpacs_ranks order by rank_id");
   while ($rankrow = $db->sql_fetchrow($result2)) {
      if ($rankrow[rank_id]==$rank_id) {
         $rankselecthtml .= "<option value =\"$rankrow[rank_id]\" selected>$rankrow[rankname]</option>";
      } else {
         $rankselecthtml .= "<option value =\"$rankrow[rank_id]\" >$rankrow[rankname]</option>";
      }
   }
   $rankselecthtml .= "</select></td>";

// Load Flag images
   $urlofimages="$IMAGEPATH/modules/MILPACS/images/flags/";
   $flagselecthtml = "<select name=\"flag\">";
   $flagselecthtml .= "<option value=\"\">Select Flag Image</option>";
   if ($handle=@opendir($urlofimages)) {
      while ($imgfile = readdir($handle)) {
         if ($imgfile != "." && $imgfile != ".." && $imgfile != "" && $imgfile != "index.html" && $imgfile != "WS_FTP.LOG" && $imgfile != "Thumbs.db") {
            if ($imgfile==$flag) {
               $flagselecthtml .= "<option value =\"$imgfile\" selected>$imgfile</option>";
            } else {
               $flagselecthtml .= "<option value =\"$imgfile\" >$imgfile</option>";
            }
         }
      }
      @closedir($handle);
   }
   $flagselecthtml .= "</select></td>";

// Load Weapons
   $weaponselecthtml = "<select name=\"weapon_id\">";
   $weaponselecthtml .= "<option value=\"\">Select Weapon</option>";
    $result3 = $db->sql_query("SELECT * FROM " . $prefix . "_milpacs_weapons order by make");
   while ($weaponrow = $db->sql_fetchrow($result3)) {
      if ($weaponrow[weapon_id]==$weapon_id) {
         $weaponselecthtml .= "<option value =\"$weaponrow[weapon_id]\" selected>$weaponrow[make]</option>";
      } else {
         $weaponselecthtml .= "<option value =\"$weaponrow[weapon_id]\" >$weaponrow[make]</option>";
      }
   }
   $weaponselecthtml .= "</select>";

// Load Unit
   $unitselecthtml = "<select name=\"unit_id\">";
   $unitselecthtml .= "<option value=\"\">Select Unit</option>";
    $result4 = $db->sql_query("SELECT * FROM " . $prefix . "_milpacs_units order by unit_name");
   while ($unitrow = $db->sql_fetchrow($result4)) {
      if ($unitrow[unit_id]==$unit_id) {
         $unitselecthtml .= "<option value =\"$unitrow[unit_id]\" selected>$unitrow[unit_name]</option>";
      } else {
         $unitselecthtml .= "<option value =\"$unitrow[unit_id]\" >$unitrow[unit_name]</option>";
      }
   }
   $unitselecthtml .= "</select>";   

// Load Status
$statusselecthtml = "<select name=\"status\">\n<option value=\"\">Select Status</option>";
$wStatus = array("Active", "LOA", "Reserves", "Retired", "Discharged");
for ($i=0; $i < sizeof($wStatus); $i++) {
   if ($status == $wStatus[$i])
      $statusselecthtml .= "<option value='$wStatus[$i]' selected>$wStatus[$i]</option>";
   else
      $statusselecthtml .= "<option value='$wStatus[$i]'>$wStatus[$i]</option>";
}
$statusselecthtml .= "</select>";
OpenTable();
echo "<p><a href=\"admin.php?op=milpacs\">Return to Main Administration</a></p>";
echo "<form name=\"addsoldier\" action=\"".$admin_file.".php\" method=\"post\">"
?>
<table width="100%" border="2" cellpadding="2" align="center" cellspacing="0" style="border-collapse: collapse;" bordercolor="#111111">
   <tr>
      <td align="center" bgcolor= "<?php echo $bgcolor2 ?>"><b><font class="title">Add a New Soldier!</font></b></td>
   </tr>
   <tr>
      <td align="center" bgcolor= "<?php echo $bgcolor1 ?>"> Uniform image: <?php echo $uniformselecthtml ?></td>
   </tr>
   <tr>
      <td align="center" bgcolor= "<?php echo $bgcolor1 ?>"> Rank image: <?php echo $rankselecthtml ?></td>
   </tr>
   <tr>
      <td align="center" bgcolor= "<?php echo $bgcolor1 ?>"> Flag image: <?php echo $flagselecthtml ?></td>
   </tr>
   <tr>
      <td align="center" bgcolor= "<?php echo $bgcolor1 ?>">Is Member:  <?php echo $ismember ?><input type="checkbox" name="ismember" value="1" ></td>
   </tr>
</table>
<table width="100%" border="2" cellpadding="2" align="center" cellspacing="0" style="border-collapse: collapse;" bordercolor="#111111">
   <tr>
      <td height="25" colspan="2" align="left" bgcolor= <?php echo $bgcolor2 ?>><b>Vital Statistics</b>
      </td>
   </tr>
   <tr>
      <td align="center" bgcolor= <?php echo $bgcolor2 ?>>
</table>
<table width="100%" border="1" cellpadding="2" cellspacing="1" style="border-collapse: collapse;" id="AutoNumber1" bordercolor="#111111">
       </td>
   </tr>
   <tr>
          <td width="50%" align="right"><b><font class="content">Name:</font></b></td>
        <td width="50%"><input type="text" name="u_name"></td>
    </tr>
   <tr>
          <td width="50%" align="right"><b><font class="content">(For Drill Access) Nuke Name:</font></b></td>
          <td width="50%"><input type="text" name="nukeusername"></td>
    </tr>
   <tr>
      <td width="50%" align="right"><b><font class="content">Location:</font></b></td>
      <td width="50%"><input type="text" name="location" value="<?php echo $location ?>"/></td>
   </tr>
   <tr>
      <td width="50%" align="right"><b><font class="content">Status:  </font></b></td>
      <td width="50%"><?php echo $statusselecthtml ?></td>
   </tr>
   <tr>
      <td width="50%"><p align="right"><font class="content"><b>Primary MOS:</b></font></td>
      <td width="50%"><input type="text" name="p_mos" value="<?php echo $p_mos ?>"/></td>
   </tr>
   <tr>
      <td width="50%" align="right"><b><font class="content">Combat Unit:</font></b></td>
      <td width="50%"><?php echo $unitselecthtml ?></td>
   </tr>
   <tr>
      <td width="50%"><p align="right"><font class="content"><b>Reports to:</b></font></td>
      <td width="50%"><input type="text" name="reports" value="<?php echo $reports ?>"/></td>
   </tr>
   <tr>
      <td width="50%" align="right"><b><font class="content">Position:</font></b></td>
      <td width="50%"><input type="text" name="position" value="<?php echo $position ?>"/></td>
   </tr>
   <tr>
      <td width="50%" align="right"><font class="content"><b>Weapon:</b></font></td>
      <td width="50%"><?php echo $weaponselecthtml ?></td>
   </tr>
    <tr>
      <td width="50%" align="right"><b><font class="content">Enlisted Date:</font></b></td>
      <td width="50%"><input type="text" name="enlistment_dt" value="<?php echo $enlistment_dt ?>"/>
      <a href="javascript:showCal('addEnlistment');"><img src="modules/MILPACS/images/icon_calendar.gif" title="Select Date" alt="Select Date"></a>
      </td>
   </tr>
   <tr>
      <td width="50%" align="right"><b><font class="content">ICQ#:  </font></b></td>
      <td width="50%"><input type="text" name="icq" value="<?php echo $icq ?>"/></td>
   </tr>   
</table>
<br>

<input type="hidden" name="op" value="NewSoldier"/>
<input type="hidden" name="id" value="<?php echo $id ?>"/>
<input type="submit" class="button" align="center" value="Add"/>
</form>
<?php
CloseTable();
@include_once("footer.php");
?>
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©