I have read like 10 tutorials on how to update database info, I have tried at least 3 different ways, but nothing works. This code below always echo "Success", though it doesn´t update if I check the database.
if(isset($_POST['update']))
{
$dbhost = 'host';
$dbuser = 'user';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$name= $_POST['name'];
$sql = "UPDATE table SET name='$name' WHERE id='$id'";
mysql_select_db('my_db');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Success">";
mysql_close($conn);
}
else
{
include"db.inc.php";
$id = $_GET["id"];
$order = "SELECT * FROM table where id='$id'";
$result = mysql_query($order);
$row = mysql_fetch_array($result);
}
?>
<form id="update" name="update" method="post" role="form" action="">
<input type="text" id="name" name="name" value="<? echo "$row[name]"?>" />
<input name="update" type="submit" id="update" value="Save">
</form>
<?php
}
?>
I don´t know what I am doing wrong...any help would be appreciated!
Aucun commentaire:
Enregistrer un commentaire