php中更新数据的问题

时间:2011-04-24 19:20:06

标签: php mysql

$query ="SELECT * FROM activites";
$queryc = mysql_query($query); 
while( $row = mysql_fetch_array($queryc))
{ 
  echo '<table>';
  echo '<tr><th colspan="3"><form action="CRUD/modiftitle.php" method="POST"><input    type="text" name="title" value="'.$row['title'].'" /><input type="submit" name="modify" value="Modify" /></form></th></tr>';
  echo '</table><br />';
 }
echo '</center>';
?> 

我有这个代码,问题是,当我尝试修改一个数据时,他们将与修改后的相同! 这是修改文件:

<?php
$connection = @mysql_connect(localhost, 'root', '');
if (!$connection){
  echo 'not connect';
}
mysql_select_db('bena');

//Update content
$content = $_POST['content'];
$sql = "UPDATE activites SET content = '$content'";

$result = mysql_query( $sql, $connection );
if($result)
echo "Update was successfully complete! ";

?>

1 个答案:

答案 0 :(得分:1)

查询UPDATE activites SET content = '$content'需要一个WHERE语句,该语句描述了应该更新的对象