简体   繁体   English

如何更新特定用户? update.php

[英]how to update specific user ? update.php

Below is my update.php code. 以下是我的update.php代码。 However, I am seeking for code to update specific user. 但是,我正在寻找更新特定用户的代码。 For example 例如

Search Id: _ __ _ __ _ __ _ _ [search] 搜索ID:_ __ __ _ _ _ _ _ _ [搜索]

If the user wants to search id details for id : 11 如果用户要搜索ID详细信息以获取ID:11

Then update.php will show open a page that can update that 11 details. 然后update.php将显示打开的页面,该页面可以更新11个详细信息。

For my code, it is not specific. 对于我的代码,它不是特定的。

Hope someone can help me please. 希望有人可以帮助我。

update.php update.php

<center>
<h1><u>Library Database</u></h1>
</center>
<?php
$con = mysql_connect("localhost","root","");
if(!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("c_database",$con);
if(isset($_POST['update'])){
$UpdateQuery="UPDATE myaduan SET id='$_POST[id]', nama_pengadu='$_POST[nama_pengadu]' WHERE id='$_POST[hidden]'";
mysql_query($UpdateQuery,$con);
};
if(isset($_POST['delete'])){
$DeleteQuery="DELETE FROM myaduan WHERE id='$_POST[hidden]'";
mysql_query($DeleteQuery,$con);
};
$sql="SELECT * FROM myaduan";
$myEdit=mysql_query($sql,$con);
echo "<table style=border:1px solid silver cellpadding=5px cellspacing=0px align=center border=0>
<tr>
<td colspan=4 style=background:0066FF; color:#FFFFFF; fontsize: 20px>UPDATE RECORD</td></tr>
<tr>
<td>ISBN</td>
<td>Title</td>
</tr>";
while($record = mysql_fetch_array($myEdit)){
echo "<form action=update.php method=post>";
echo "<tr>";
echo "<td>" . "<input type=text name=id value=".$record['id'] . " </td>";
echo "<td>" . "<input type=text name=nama_pengadu value=".$record['nama_pengadu']. " </td>";
echo "<td>". "<input type=hidden name=hidden value=".$record['id']. " </td>";
echo "<td>"."<input type=submit name=update value=update"." </td>";
echo "<td>"."<input type=submit name=delete value=delete"." </td>";
echo "</tr>";
echo"</form>";
}
echo"</table>";
mysql_close($con);
?>

First of all you should stop using mysql_connect . 首先,您应该停止使用mysql_connect。 It was deprecated , instead use another one such as PDO. 不推荐使用,而是使用另一个,例如PDO。 You can run a query to display all your users then have tow links in front of each one like: -User1 update * delete * -User2 update * delete * . 您可以运行查询以显示所有用户,然后在每个用户前面都有两个链接,例如:-User1 更新 * 删除 * -User2 更新 * 删除 *。 . . if u hit delete you post all your info to ur processing page and delete the user .If you hit update you load a form to another div using Jquery/ajax or you redirect to another page with your form on it and you update your user info . 如果您点击删除,则将所有信息发布到您的处理页面并删除用户。如果您点击更新,则使用Jquery / ajax将表单加载到另一个div,或者您重定向到包含表单的另一个页面,并更新用户信息。 This way you ll have a cleaner/user freindly area to do your thing . 这样,您将有一个清洁工/用户友好的区域来做您的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM