Default Re: Mga Tanong tungkol sa PHP, CSS, jquery, HTML at MySQL pasok D2
Pa help sa update code ko po, na-uupdate niya kasi lahat ng nasa tables ko.
ano po problem sa query?

Here's my code for my update, the problem is when i submit, it updates all the data in my table.. what is wrong????


						$upd="update news set title='$_POST[title]',date='$_POST[date]',post='$_POST[post]'";
						$msg="you have updated";

Reply With Quote

You need to add a 'WHERE' clause in your statement. For example:

$upd="update news set title='$_POST[title]',date='$_POST[date]',post='$_POST[post]' WHERE id = '$_POST[id]'";

This assumes that there is a hidden field in your form that has the unique value of the entry you are editing.

I should also add that it is bad practice to execute sql statements without sanitising the inputs.

You also need your post data in '' and either use {} or '".."' around them:

$upd="update news set title='".$_POST['title']."',date='".$_POST['date']."',post='".$_POST['post']."' WHERE id = '".$_POST['id']."'";