I created a system that will update database, I want to update database by the remaining custody will output from the equation which happens inside $calc_of_custody after I assigned number of custody on an user , I have 3 tables (users, custody, assigned_custody) I tried many ideas but it's only update last checkbox without the above check-boxes , if I have (50 shirts, 100 maintenance tools and 10 hammers ) and the user Edwin will get
shirts 10 maintenance tools 30 hammers 13
I'll retrieve user from users table, custody from custody table and insert them into assigned_custody then update the remaining custody into the custody table, how could I do that ?
the below is snippet from my code
first section is the function.php
function quant_custody($id){
global $con;
$query = "SELECT quant FROM custody_type WHERE id = '$id'";
$result = mysqli_query($con,$query);
$row = mysqli_fetch_assoc($result);
return $row['quant'];
}
function username_custody($id){
global $con;
$query = "SELECT username FROM users WHERE id = '$id'";
$result = mysqli_query($con,$query);
$row = mysqli_fetch_assoc($result);
return $row['username'];
}
function name_custody($id){
global $con;
$query = "SELECT name FROM custody_type WHERE id = '$id'";
$result = mysqli_query($con,$query);
$row = mysqli_fetch_assoc($result);
return $row['name'];
}
second section is a main page:
<?php include_once('../include/config.php') ?>
<?php include_once('../include/functions.php') ?>
<?php
if(isset($_POST['submit'])){
$cust = $_POST['custody'];
$usr = $_POST['user'];
$quant_on_user = $_POST['number'];
$get_quant = quant_custody($cust);
$get_username = username_custody($usr);
$get_namecustody = name_custody($cust);
$calc_of_custody = $get_quant - $quant_on_user;
if($calc_of_custody < 0 ){
echo"there's no enough custody";
exit;
}else{
update_custody_type($calc_of_custody,$cust);
}
/*echo $cust." ".$usr." ".$number;*/
$query = "INSERT INTO assigned_custody (user_name, custody_name, custody_q) VALUES ('$get_username','$get_namecustody','$quant_on_user')";
$result = mysqli_query($con, $query);
?>
<form action="" method="post">
<!--
THE BELOW SECTION FOR A USERS
-->
<?php
$query = "SELECT * FROM users";
$result = mysqli_query($con,$query);
?>
<select name="user">
<?php while($row= mysqli_fetch_assoc($result)){ ?>
<option value='<?php echo $row['id'];?>' >
<?php echo $row['username'];?>
</option>
<?php } ?>
</select>
<!--
THE BELOW SECTION FOR A CUSTODIES
-->
<?php
$query = "SELECT * FROM custody_type";
$result = mysqli_query($con,$query);
while($row= mysqli_fetch_assoc($result)){
$i = 1;
echo "<br>".$row['name']." "; ?>
<input type="checkbox" name="custody" value='<?php echo $row['id'];?>'>
<input type="number" value='' name="number"> <br>
<?php
}
?>
<input type="submit" name="submit">
</form>
Aucun commentaire:
Enregistrer un commentaire