Jump to content

Need Help Urgently!


Go to solution Solved by QuickOldCar,

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
https://forums.phpfreaks.com/topic/288431-need-help-urgently/
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
https://forums.phpfreaks.com/topic/288431-need-help-urgently/#findComment-1479190
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.