PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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.
$update = "UPDATE post SET `title`='$_POST[inputTitle]', `creator`='$_POST[inputCreator]' WHERE ID= $_POST[id]";
mysql_query($query) or die (mysql_error());
You're defining the query as $update, then trying to execute $query.
You're also using deprecated mysql_* functions, aren't validating or sanitizing your inputs, aren't using prepared statements, etc.
It updates now but I also get an error message. please help me why i'm getting this? Thanks in advance.
DB Error, could not query the database MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
if( isset($_POST['newTitle']) )
{
$newTitle = $_POST['newTitle'];
$id = $_POST['id'];
$sql = "UPDATE post SET title='$newTitle' WHERE id='$id'";
$res = mysql_query($sql) or die("Could not update".mysql_error());
echo "<meta http-equiv='refresh' content='0;url=page.php'>";
}
DB Error, could not query the database MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1