Php modifies the function for updating database user records

Source: Internet
Author: User

$ Link_id = mysql_connect ("localhist", "root", "qwaszx") or die ("connection failed! ");
If ($ link_id)
{
Mysql_select_db ("my_test ");
If (! $ _ GET [id])
 {
$ Result = mysql_query ("select * from userinfo ");
Echo "<TABLE border = 1>
<TR>
<TD> No. </TD>
<TD> user name </TD>
<TD> Gender </TD>
<TD> age </TD>
<TD> Registration time </TD>
<TD> Operation </TD>
</TR> ";
While ($ row = mysql_fetch_array ($ result ))
  {
Echo "<TR>
<TD> ". $ row [id]." </TD>
<TD> ". $ row [uername]." </TD>
<TD> ". $ row [gender]." </TD>
<TD> ". $ row [age]." </TD>
<TD> ". $ row [regdate]." </TD>
<TD> <a href = modify. php? Id = ". $ row [id]."> edit </a> </TD>
</TR> ";
  }
Echo "</TABLE> ";
} Else
 {
If (! $ _ POST [OK])
  {
$ SQL = "select * frim userinfo where id =". $ _ GET [id];
$ Result = mysql_query ($ SQL );
$ Row = mysql_fetch_array ($ result );
?>
<Form method = post action = 'modify. php? Id = <? Echo $ _ GET [id];?> '>
<?
Echo $ row [id]. "<br> ";
?>
<Input type = "hidden" name = "id" value = <? Echo $ row [id];? >>>
Name <input type = text name = "uername" value = <? Echo $ row [uername];?> <Br>
Gender <input type = text name = "gender" value = <? Echo $ row [gender];? >> <Br>
Age <input type = text name = "age" value = <? Echo $ row [age];? >> <Br>
Registration time <input type = text name = "regdate" value = <? Echo $ row [regdate];? >> <Br>
<Input type = submit name = OK value = "submit">
</Form>
<?
} Else
  {
$ SQL = "update userinfo set username = '". $ _ POST [username]. "', gender = '". $ _ POST [gender]. "', age = '". $ _ POST [age]. "', regdate = '". $ _ POST [regdate]. "'Where id = '". $ _ POST [id]. "'";
$ Result = mysql_query ($ SQL );
If ($ result)
Echo "the record has been successfully modified <br>" <a href = 'modify. Php'> continue to modify the record </a>;
Else
Echo "failed to record modification <br> <a href = modify. php? Id = ". $ _ POST [id]."> Return </a> ";
  }
 }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.