$ 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> ";
}
}
}