lundi 24 février 2020

HELPPP PHP/ MYSQL [closed]

Basically I am creating a lost items website for uni.

I have every other part working except item approve/ decline buttons.

what I need it to do it so update the database and change a value from 'N' to 'Y' where the ID matches

code below:

<?php session_start(); ?>
<?php require 'includes/config.php'?>
<?php include("includes/header.php");?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="container" id="main-content">
        <h2>Requests
</h2>
<?php
        $sql = "SELECT * FROM requests r, items i WHERE r.id = i.id ";
        $ava = $db->query($sql);
        if( isset($_SESSION['personId'])) { 
        ?>
<?php
while($requests = mysqli_fetch_assoc($ava)): ?>
   <form action="Requests.php" method="post">
           <h4> <?= $requests['title']; ?> </h4>
           <img src="<?= $requests['image']; ?>" style="width:400px;height:300px;"/>
           <div></div>
           <a>Category : </a> <p>  <?= $requests['category']; ?> </p>
           <a>Date Found : </a> <p>  <?= $requests['foundDate']; ?> </p>  
           <a>Description : </a> <p> <?= $requests['description']; ?> </p>
           <a>location Found : </a> <p> <?= $requests['location']; ?> </p>
           <a>Who Found it : </a> <p> <?= $requests['foundBy']; ?> </p>
           <a>item Id </a> <p>  <?= $requests['id']; ?> </p>
           <a>Person ID </a> <p>  <?= $requests['personId']; ?> </p>  
          <div></div>
           <input type="submit" name="approve" value="Approve"></input>
           <input type="submit" name="decline" value="Decline"></input>
   </form>
<?php endwhile; 
        }
?>
<?php
if( isset($_POST['approve'])) { 
        $id = $_POST['id'];

        $sql = "UPDATE items  SET claimed = 'Y' WHERE id = $id ";
        if(mysqli_query($db, $sql)){
                echo "Records were updated successfully.";
          } else {
                echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
                exit();
          }
}
if( isset($_POST['decline'])) {         
}
?>
</div>
<?php include("includes/footer.php");?>

</body>
</html>

i believe my issue lies in the SQL update statement, I need a way to distinguish between the items...

Thanks in advance!!!




Aucun commentaire:

Enregistrer un commentaire