I’m trying to update my MYSQL table based on whether or not the user wants to mark an item off a list. SO if item A is checked, Uncheck it. if item A is unchecked, Check it. When i use my script below nothing happens and I’m not sure why or whats even going wrong. No errors are thrown. This is ran when the user pushes the check button. It sends it to variables id and c.
$_GET[‘c’] should always be a 1 or a 0, Id is a uniqid()
<?php
require_once('db.php');
if(!isset($_GET['id'])){
echo "You didn't supply a item (id)";
header('HTTP/1.1 417 Expectation Failed');
exit();
}
if(!isset($_GET['c'])){
echo "You didn't supply a item (c)";
header('HTTP/1.1 417 Expectation Failed');
exit();
}
if ( $_GET['c'] == 0 )
{
$query = "UPDATE todo_item
SET checked = 1
WHERE todo_id = :id";
}
else
{
$query = "UPDATE todo_item
SET checked = 0
WHERE todo_id = :id";
}
$id = $_GET['id'];
$statement = $db->prepare($query);
$statement -> execute(array(
'todo_id' =>$id,
));
header("Location: index.php");
?>
I think you are passing the wrong parameter to
execute. Try this: