My update query is not working with my variable $id BUT does work when I use the literal number 29, for example. I have var_dumped $id and I get INT(29). Has something changed recently because I copied code that has worked in the past.
$id = (ISSET($_GET['id'])) ? intval($_GET['id']):0;//prevents sql inject
var_dump($id);
My query that works is the following:
$sqlUpdate = $db->query("UPDATE sites SET site_name='$site_name',population='$population' WHERE id=29");
This query doesn't work:
$sqlUpdate = $db->query("UPDATE sites SET site_name='$site_name',population='$population' WHERE id=$id");
I found my issue/answer. I used <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
within my form because the code to process my form posts resides within the same file. Upon hitting 'UPDATE' I noticed in the address bar that the filename was correct but it dropped the GET variable for a brief moment. At this time, the following code ran again...
$id = (ISSET($_GET['id'])) ? intval($_GET['id']):0;
$id = protect($db,$id);
and my variable $id was changed from the correct GET value to 0, thus preventing my code from updating the correct record. I changed my code to the following:
<form method="post" action="">
and everything update perfectly. If anyone cares to explain WHY this happened I would greatly appreciate it.