I am currently trying to create a webpage which can edit details of members of a club. I have a button that Revokes their access to the club. This button is displayed in each row of the HTML table. When the button is pressed, it triggers the function revoke()
and should update the database to make their status "revoked".
However in my PHP, i can't seem to be able to get it to work in the WHERE clause. It should be WHERE intID = "whatever their id is"
but it doesn't work. I think this is because i am having trouble passing the ID to the SQL statement.
Here is my code:
function revoke(intID1){
<?php
$intID=intID1;
$conn = new mysqli("my server name", "username", "pword", "database");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE `members` SET `Status`='Revoked' WHERE `intID`=$intID";
if ($conn->query($sql) === TRUE) {
echo "alert('Record updated successfully')";
} else {
echo "alert('Error updating record')". $conn->error;
}
$conn->close();
?>
}
I am pretty sure the trouble lays in this line:
$sql = "UPDATE `members` SET `Status`='Revoked' WHERE `intID`=$intID";
I have tried changing the $intID
to '$intID'
and messing around with quotation marks but still can't get it to work. I have even tried using intID1
which is the one originally passed into the function.
I have looked around and found bits about the mysql real escape string but couldn't get that to work either.
Hopefully you guys can help. Thanks in advance.