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
if
will always returntrue
if there are data in the tabletests
and will never enter theelseif
to executeupdate
, try to change thiselseif
by onlyif
and do thesubmit
ofform
again.– 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