Jump to content

Need Help Urgently!


dapcigar

Recommended Posts

I want to subtract a value from a table and update it with the new value. i don't get the desired result everytime i do it. please what am i doing wrong?

 

    <?php
$id = $_GET['id'];
?>
<?php



include('mysql_connect.php');


// select departnemt
$sql1 = mysql_query("SELECT * FROM requisition WHERE id = '$id' ");
        $dept = mysql_fetch_array($sql1);
        
     
$amount = $dept ['amount'];    
$department = $dept['department'];


// select the budget DB

$sql2 = mysql_query("SELECT *  FROM budget WHERE department = '$department' ");
        $budget = mysql_fetch_array($sql1);        
    
                        
    $actual = $budget['actual'] ;

       
    $final = ($actual - $amount);            

$r = mysql_query("UPDATE budget SET actual = '$final'  WHERE department = '$department'") or die(mysql_error());

$q = mysql_query("UPDATE requisition SET status = 'Paid'  WHERE id = '$id'") or die(mysql_error());


header("Location: approved_req.php");

?>

 

thanks in advance

Link to comment
Share on other sites

Please i need help with something else..

 

Am loading data from the database to a dropdown list. but when i want to save it back to the DB, it is saving the ID and not the name.

here is the HTML form

 

<form class="form-horizontal" method="post" action="rec_proc.php?process=true">
                  <fieldset>
                    <legend>Requisition Form</legend>
                    <div class="control-group">
                      <label class="control-label" for="focusedInput">First Name:</label>
                      <div class="controls">
                                  <span class="input-xlarge uneditable-input"><?php echo $firstname ?></span>
                      </div>
                    </div>
                    <div class="control-group">
                      <label class="control-label" for="focusedInput">Department :</label>
                      <div class="controls">
                                  <span class="input-xlarge uneditable-input"><?php echo $department ?></span>
                      </div>
                    </div>
                   
                    <div class="control-group">
                                <label class="control-label" for="selectError">Category :</label>
                                <div class="controls">
                                  <select id="selectError" data-rel="chosen" name="cat_name">
                                    <?php
                while($row =  mysql_fetch_array($select)){
                extract($row);?>
              <option value="<?php echo $id;?>"><?php echo $cat_name; ?></option>
                <?php }?>
                                  </select>
                                </div>
                    </div>
                    <div class="control-group">
                      <label class="control-label" for="focusedInput">Description :</label>
                      <div class="controls">
                        <input class="input-xlarge focused" id="focusedInput" type="text" name="description" value="">
                      </div>
                    </div>
                    <div class="control-group">
                                <label class="control-label" for="appendedInput">Amount :</label>
                                <div class="controls">
                                  <div class="input-append">
                                    <input id="appendedInput" size="16" type="text" name="amount"><span class="add-on">.00</span>
                                  </div>
                                  <span class="help-inline">Enter Amount</span>
                                </div>
                              </div>
                    <div class="control-group">
                      <div class="controls"></div>
                    </div>
                    <div class="form-actions">
                      <button type="submit" class="btn btn-primary">Send Requisition</button>
                      <button type="reset" class="btn">Cancel</button>
                    </div>
                  </fieldset>
                </form>

 

......................................................................................................................

 

Here is the code

 

 <?php
 
if(isset($_GET['process'])){

$cat_name = $_POST['cat_name'];

}

$description = $_POST['description'];
$amount= $_POST['amount'];

$date = date('Y-m-d');
$status = "Pending ";

include ('mysql_connect.php');


//insert into DB
$sql = mysql_query("INSERT INTO requisition ( id, department, category, description, amount, date, username, firstname, lastname, status) VALUES ( NULL, '$department', '".$cat_name."', '$description', '$amount','$date', '$user', '$firstname', '$lastname', '$status' )") or die(mysql_error());

header ( 'location: staff_dash.php');

?>

 

i want it to save the category and not the ID.. how can i correct this?

 

 

Thanks in advance

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.