0
I have the following code and when I give Submit it does not update the ANYTHING in the database.
$query = "SELECT * FROM tests WHERE ID = :ID";
$result = $db->prepare($query);
$result->execute(array(':ID' => $_REQUEST['ID']) );
if ($row = $result->fetch(PDO::FETCH_ASSOC)) { 
?>
 <br />
 <br />
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 
  <input id="Game" type="text" name="Name" value="<?php echo $row['Name]; ?>" required />
 <br />
 <input type="hidden" name="ID" value="<?php echo $row['ID']; ?>" />
 <input type="Submit" name="Submit" value="Salvar alterações" />
</form>
<? 
 } 
 elseif (isset($_POST['Submit'])) {
 $ID = $_POST['ID']; 
 $Name = $_POST['Name'];
 $queryupdate = "UPDATE tests SET Name = :Name WHERE ID= :ID";  
 $q = $db->prepare($queryupdate);
 $q->execute(array(":ID" => $ID, ":Name" => $Name));
 header ('Location: edit.php');}
From what I understand of your code, your
ifwill always returntrueif there are data in the tabletestsand will never enter theelseifto executeupdate, try to change thiselseifby onlyifand do thesubmitofformagain.– abfurlan
It worked, you can tell me why I can’t find the
elseif? Answer with this and I give a right in your answer to get more points !– thecreator