updating data using php
Posted: Thu Mar 26, 2015 5:22 pm
Hello guys, I have created a form where users can edit their post, everything works correctly but when the user clicks on the "edit" button it doesn't update. It display "Query was empty" any idea where I have gone wrong? Thank in advance.
Code: Select all
<?php
$connect = mysql_connect("igor.gold.ac.uk","ma301sl","fitnesspal1") or die ("couldn't connect!");
mysql_select_db("ma301sl_blog") or die("couldn't find db");
if(!isset($_POST['submit'])) {
$query = "SELECT * FROM post WHERE id=$id";
$results = mysql_query($query);
$row = mysql_fetch_array($result);
}
?>
<h1>You are Modifying...</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
The title of the post<input type="text" name="inputTitle" value="<?php echo $row['title']; ?>" />
Creator<input type="text" name="inputCreator" value="<?php echo $row['creator']; ?>" />
Body of the post<textarea name="inputText" value="<?php echo $row['body']; ?>"> </textarea>
<input type="hidden" name="id" value="<?php $_GET['id']; ?>" />
<input type="submit" name="submit" value="Edit" />
</form>
<?php
if(isset($_POST['submit'])) {
$update = "UPDATE post SET `title`='$_POST[inputTitle]', `creator`='$_POST[inputCreator]' WHERE ID= $_POST[id]";
mysql_query($query) or die (mysql_error());
echo "user has been midified";
header("Location: page.php");
}
?>