probably a really simple fix but I'm stuck.
what I need this to do it to be able to approve an item, which then the SQL statement will update the claimed column for the specific item to a 'Y' i am able to update the whole claimed column but i can't seem to update 1 specific item.
I've tried declaring a variable $id and have tried to set it as the ID of the item but have now hit a brick wall.
apologies in advance I'm pretty new to php.
hopefully, the question is structured correctly...
This is the error i receive:
ERROR: Not able to execute You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1 UPDATE items SET claimed = 'Y' WHERE id =
<?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>
<input type="hidden" name="itemId" <?= $requests['id']; ?> />
<a>Id:</a> <p> <?= $requests['id']; ?> </p>
<input type="hidden" name="personId" <?= $requests['personId']; ?> />
<a>Proof or Ownership </a> <p> <?= $requests['proof']; ?> </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['itemId'];
$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 ". mysqli_error($db) . $sql;
exit();
}
}
if( isset($_POST['decline'])) {
}
?>
</div>
<?php include("includes/footer.php");?>
</body>
</html>
any help is appreciated thanks :)
Aucun commentaire:
Enregistrer un commentaire