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 01, 2005 1:13 pm Reply with quote

I am adding another page to my custom module I am working on but every time I submit the form to add data to the MySQL table I get the "Sorry, this Module isn't active!"

Can't seem to figure out where I am going wrong.

Any help is appreciated.

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 Points                                            */
/*********************************************************/
if (stristr($_SERVER['SCRIPT_NAME'], "addpoints.php")) {
    Header("Location: ../../index.php");
    die();
}
if (!in_groups('1-10-23')) {
   // Not authorized
    echo "<META HTTP-EQUIV=\"refresh\" content=\".1;URL=modules.php?name=MILPACS&file=accessdenied\">";
   echo "<a href=\"modules.php?name=MILPACS&file=accessdenied\">";
}

$index = 0;

//finds the server's root directory
$self = dirname(__FILE__);
$nukemod = basename($self);
$rootdir = eregi_replace("/modules/$nukemod", "", $self);
require_once("mainfile.php");
@include_once("header.php");
$module_name = basename(dirname(__FILE__));
global $module_name, $db, $prefix;

   OpenTable();

if ($op == "addpoints") {
      // Validations go here      
      // If all validations passed, save and exit, otherwise, redisplay with errors
      //convert all the posts to variables:
      $point_id = intval($_POST['point_id']);
      $point_dt = addslashes($_POST['point_dt']);      
      $points = intval($_POST['points']);
      $id = intval($_GET['id']);      
      $pdetails = $_POST['pdetails'];
      //Insert the values into the correct database with the right fields
      $result=MYSQL_QUERY ("INSERT INTO " . $prefix . "_milpacs_points_lkup (pid, point_id, point_dt, points, uniqueid, pdetail)".
         "VALUES ('NULL','$point_id','$point_dt','$points', '$id', '$pdetails')");      
      }

?>   
<form method="post" name="addpoints" action="modules.php?name=<? echo basename(dirname(__FILE__))?>"> 
<!-- <form name="addpoints" action="modules.php?name=<?php echo $module_name ?>" method="post"> -->
<table border="2" cellpadding="2" align="center" cellspacing="0" style="border-collapse: collapse;" bgcolor="#000000" bordercolor="#111111" width="100%">
   <tr>
      <td align="center" bgcolor="#777777">
      <b><font color="#000000">Record points for this soldier.</font></b>
      </td>
   <tr>
      <td align="left" bgcolor="#666633">
      <b><font color="#000000">Add Points</font></b>
      </td>
   </tr>
<table border=0 width="100%" cellpadding="3">
   <tr>
      <th width="20%">Reason for Action</th>
      <th width="20%">Point Value</th>
      <th width="25%">Date of Action</th>
      <th width="30%"><b>Details</b></th>
   </tr>
   <tr>
      <td align="center" bgcolor="#999999">
      <select name="point_id" size="1">
      <option value="">--- Select Action ---</option>
<?php
// Get values to populate combo box
$result = $db->sql_query("SELECT point_id, point_class FROM " . $prefix . "_milpacs_points WHERE action = 'A'");
while ( $row = $db->sql_fetchrow($result) ) {
   $pclass = $row["point_class"];
   $point_id = $row["point_id"];
         echo "<option >$pclass</option>";   
}
?>
      </select>
      </td>      
         <td align="left" valign="middle" bgcolor="#999999">Points:<br>
            <input type="radio" name="points" checked value=""> Other&nbsp;
         <input type="text" name="points" value="0" size="10">
            <input type="radio" name="points" value="1"> 1 Point<br>
            <input type="radio" name="points" value="5"> 5 Points<br>
         <input type="radio" name="points" value="10"> 10 Points<br>
         <input type="radio" name="points" value="25"> 25 Points<br>
      </td>       
      <td align="center" bgcolor="#999999">
      <input type="text" name="point_dt" value="<?php echo $point_dt ?>">
      <a href="javascript:showCal('PointDate');"><img src="images/javascript/calendar.jpg" title="Select Date" alt="Select Date"></a>
      <font style="color: red;"><?php echo $dt_error ?></font>
      </td>
      <td align="left" bgcolor="#999999">
      <textarea name="details" cols="35" colspan="3" rows="3"><?php echo $pdetails ?></textarea>
      </td>
   </tr>
</table>
<br>
<input type="hidden" name="op" value="addpoints"/>
<input type="hidden" name="id" value="<?php echo $id ?>"/>
<input type="submit" align="center" name="Submit" value="Add"/>
</form>
<?php
CloseTable();
@include_once("footer.php");
?>


I have tried both of these with no luck

Code:


<form method="post" name="addpoints" action="modules.php?name=<? echo basename(dirname(__FILE__))?>"> 


<form name="addpoints" action="modules.php?name=<?php echo $module_name ?>" method="post">
 
View user's profile Send private message Visit poster's website ICQ Number
Donovan







PostPosted: Thu Jun 02, 2005 11:41 am Reply with quote

I made a change to another of my MILPACS pages and pointed it to the correct module. Now when I hit submit on the addpoints.php I get "Sorry, that module file was not found."

any ideas?
 
Donovan







PostPosted: Mon Jun 06, 2005 12:43 pm Reply with quote

Anybody?

Kinda stuck on this one.

Is my $module_name variable getting stepped on?
 
Donovan







PostPosted: Tue Jun 07, 2005 7:30 am Reply with quote

Still can't figure this out.

Here is what is in my index.php


Code:
switch ($op) {

   case "editsoldier":
   case "savesoldier":
      @include_once("admin/editsoldier.php");
       break;
   case "editservice":
   case "saveservice":
   case "delservice":
      @include_once("admin/editservice.php");
       break;
   case "editmedal":
   case "savemedal":
   case "delmedal":
      @include_once("admin/editmedalrecord.php");
       break;
   case "drillreport":
   case "saveDrillReport":
      @include_once("admin/drillreport.php");
      break;
   case "addpoints":   
      @include_once("admin/addpoints.php");
      break;
   case "removepoints":   
      @include_once("admin/removepoints.php");
      break;
   default:
 
kguske
Site Admin



Joined: Jun 04, 2004
Posts: 6437

PostPosted: Tue Jun 07, 2005 9:43 am Reply with quote

Sorry for not responding sooner, Donovan. I'll take a look at this tonight.

_________________
I search, therefore I exist...
Only registered users can see links on this board! Get registered or login!
 
View user's profile Send private message
kguske







PostPosted: Wed Jun 08, 2005 5:18 am Reply with quote

Took a look, though later than expected. Didn't see the error you mentioned above, but found a couple of other things. Take a look now and you'll see an SQL error. I added a few lines of code to conditionally display the error. I also added an extra <BR> on the Point Value selection. I think all you'll need is the correct SQL...
 
kguske







PostPosted: Wed Jun 08, 2005 5:27 am Reply with quote

An additional problem: there was no way to distinguish between displaying the form for adding point and saving points. Once I corrected the SQL by adding an s to pdetails, it tried to add a record every time the page was displayed, causing duplicates.

I changed the index.php to allow addpoints and savepoints, which corrected that. But there is still an issue with the SQL values. Is the key field auto incremented?
 
Donovan







PostPosted: Wed Jun 08, 2005 8:07 am Reply with quote

Grrrrrr.

The pid wasn't set for auto increment. It is now inserting pid, point_dt, points, and pdetails but not uniqueid, or point_id.

Point_id matches the point_id in points table to get the proper type (Combat Pay, Drills, etc).

As far as uniqueid, the addpoints page has the correct id passed to it so I was thinking this would work to capture that and insert into lkup

$uniqueid = intval($_GET['id']);


After I get everything working I need a way to display this in the soldierprofile page here.

Code:
<td width="12%" align="right">

               <b><font color="#660033">Promotion Points:  </font></b>
               </td>
               <td width="15%" colspan="2">
               <p class="content"><?php echo $promopoints  ?>
               </td>


Thinking I could just compute $promopoints by using a function.

Thanks for your help. I am learning so much from you


Last edited by Donovan on Wed Jun 08, 2005 8:24 am; edited 1 time in total 
Donovan







PostPosted: Wed Jun 08, 2005 8:22 am Reply with quote

Would something like this work?

Code:
$query = "SELECT SUM(".$points.") as sum FROM ".$prefix . "_milpacs_points_lkup." WHERE uniqueid ='$id' ";


$result_array = mysql_fetch_array(mysql_query($query));
$promopoints += $result_array[sum];
}

<td width="15%" colspan="2">
               <p class="content"><?php echo $promopoints  ?>
               </td>;


It's amazing what you can find on the web. Smile
 
Donovan







PostPosted: Wed Jun 08, 2005 9:18 am Reply with quote

Well everything works now except for inserting point_id into point_lkup.

changing this from a GET to a POST fixed the uniqueid issue.
$uniqueid = intval($_POST['id']);

Now a question I have is this.

My sql statement is
Code:
 $result = $db->sql_query ("INSERT INTO " . $prefix . "_milpacs_points_lkup (pid, point_id, point_dt, points, uniqueid, pdetails)".

         "VALUES ('NULL','$point_id','$point_dt','$points', '$uniqueid', '$pdetails')");


However I think I need to pull the point_id from the points table where I have
point_id
point_class.

The code in addpoints just displays the dropdown box. I need to match the value in the drop down to point_id in the points table and insert into points_lkup.

My drop down code is the following:

Code:
<select name="point_id" size="1">

      <option value="">--- Select Action ---</option>
<?php
// Get values to populate combo box
$result = $db->sql_query("SELECT point_id, point_class FROM " . $prefix . "_milpacs_points WHERE action = 'A'");
while ( $row = $db->sql_fetchrow($result) ) {
   $pclass = $row["point_class"];
   $point_id = $row["point_id"];
         echo "<option >$pclass</option>";   
}
?>
      </select>


What is the best way to accomplish this?
 
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 ©