dapcigar Posted May 12, 2014 Share Posted May 12, 2014 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'];?><?phpinclude('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 Quote Link to comment https://forums.phpfreaks.com/topic/288431-need-help-urgently/ Share on other sites More sharing options...
Solution QuickOldCar Posted May 12, 2014 Solution Share Posted May 12, 2014 Is this supposed to be getting from $sql2? $budget = mysql_fetch_array($sql1); am guessing should be this $budget = mysql_fetch_array($sql2); Quote Link to comment https://forums.phpfreaks.com/topic/288431-need-help-urgently/#findComment-1479174 Share on other sites More sharing options...
dapcigar Posted May 12, 2014 Author Share Posted May 12, 2014 Yeah.. that solved the problem.. thanks a lot.. Quote Link to comment https://forums.phpfreaks.com/topic/288431-need-help-urgently/#findComment-1479176 Share on other sites More sharing options...
dapcigar Posted May 12, 2014 Author Share Posted May 12, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/288431-need-help-urgently/#findComment-1479190 Share on other sites More sharing options...
adam_bray Posted May 12, 2014 Share Posted May 12, 2014 You're using $id in the select list where you want to use $cat_name, change this - <option value="<?php echo $id;?>"><?php echo $cat_name; ?></option> Quote Link to comment https://forums.phpfreaks.com/topic/288431-need-help-urgently/#findComment-1479191 Share on other sites More sharing options...
Maq Posted May 13, 2014 Share Posted May 13, 2014 @dapcigar, please follow the rules and use code tags when posting code. Quote Link to comment https://forums.phpfreaks.com/topic/288431-need-help-urgently/#findComment-1479360 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.