-1
I am unable to update my fields. Where I am missing?
Caught the id
through GET
and I can display the table data, but I can’t update it.
CAMPOS
$id_destino = $_GET['id_destino'];
$destino = mysql_real_escape_string($_POST['destino']);
$historia = mysql_real_escape_string($_POST['historia']);
$geografia = mysql_real_escape_string($_POST['geografia']);
$clima = mysql_real_escape_string($_POST['clima']);
$cultura = mysql_real_escape_string($_POST['cultura']);
if($_POST['enviar']) {
$sql = mysql_query("UPDATE `destinos_pt` SET destino = '$destino', historia = '$historia', geografia = '$geografia', clima = '$clima', cultura = '$cultura' WHERE id_destino = '$id_destino'");
header("Location: dashboard.php");
}
FORM
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" name="destinosform" novalidate role="form">
</form>
What’s wrong I can’t update my table?
Put $sql = mysql_query("UPDATE
destinos_pt
SET destination = '$destination', history = '$history', geography = '$geography', climate = '$climate', culture = '$culture' WHERE id_destination = '$id_destination'") or die(mysql_error());– Lucas Henrique
There is the variable
$_POST['enviar']
on your form?– Lucas Henrique
Why mix GET with POST? Place the entire form, which makes it easier to try to find a solution.
– Bacco
Put php from the connection part of the database also if possible.
– Bacco
Important reading: How do you debug PHP scripts?
– brasofilo
You need to specify your code more so we can see where the bug is.
– Jorge B.
Beware of sql Injection using the parameters this way, either do a cleanup or use Prepared statements.
– Wakim