2016-03-27 26 views
-2

我正在尝试编写一个网站,其中用户有配置文件页面。我希望他们能够编辑他们已经输入的个人资料信息。但是有一个关于我的部分,用户需要包含大量有关他们自己的细节。 我已经使用了SQL UPDATE语句,它可以覆盖已经存在的数据,但是我想知道是否有方法来提取那里的数据并允许用户编辑这些数据,然后发布更新的版本到桌上? 对此方法的任何帮助都会很好。在mysql表中更新数据

回答

2

你只需做一个SELECT来在用户页面上显示用户信息,并将这些值合并到一个表单中,然后你将处理表单以更新数据(或者在同一个php文件或者另一个文件中)

我建议你访问这个教程:Create user editing area

1
The below code fetch the user info from the database and display it in a form. 


<?php $sql = "SELECT * FROM user_table where username = '$username'"; 
      $query = mysqli_query($database_connection, $sql); 
      $fetch = mysqli_fetch_assoc($query); 
      echo "<form action='update_user_info.php' method='post'> 
      <input type='text' name='full_name' value='$fetch['full_name']' > 
      <input type='text' name='address' value='$fetch['address']' > 
      <textarea title='about' name='about'>$fetch['about_user']</textarea> 
      <input type='submit' name='btn_update' value='Save'> 
</form>?> 

这里是update_user_info的样子。

<?php $sql = "UPDATE user_table SET full_name = '$_POST['full_name']' WHERE username = '$username'"; 
$query = mysqli_query($database_connection, $sql); 
//I hope you can find your way from here ?>