0
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????

Code:

	<?php 
						include("connect.php");
						if(isset($_POST['submit']))
						{
						$upd="update news set title='$_POST[title]',date='$_POST[date]',post='$_POST[post]'";
						$up=mysql_query($upd);
						$msg="you have updated";
						}
						?>



Reply With Quote
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by simplypixie
0

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.

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

Edited by pulsevortex: n/a

0

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']."'";
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.