Copy codeThe Code is as follows:
<Html>
<Head>
<Title> Insert a new data record </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
</Head>
<Body>
<Form method = "post" name = "form1" action = "insert. php">
<Table align = "center">
<Tr valign = "baseline">
<Td nowrap align = "right"> No.: </td>
<Td> <input type = "text" name = "id" value = "" size = "32"> </td>
</Tr>
<Tr valign = "baseline">
<Td nowrap align = "right"> User name: </td>
<Td> <input type = "text" name = "username" value = "" size = "32"> </td>
</Tr>
<Tr valign = "baseline">
<Td nowrap align = "right"> password: </td>
<Td> <input type = "text" name = "password" value = "" size = "32"> </td>
</Tr>
<Tr valign = "baseline">
<Td colspan = "2" nowrap> <input name = "Submit" type = "submit" value = "Submit">
<Input type = "reset" name = "Reset" value = "reset"> </td>
</Tr>
</Table>
</Form>
</Body>
</Html>
Copy codeThe Code is as follows:
<? Php
@ Mysql_connect ("localhost", "root", "1981427") // You must connect to the database server before selecting a database.
Or die ("database server connection failed ");
@ Mysql_select_db ("test") // select the database mydb
Or die ("the database does not exist or is unavailable ");
$ Id = $ _ POST ['id'];
$ Username = $ _ POST ['username'];
$ Password = $ _ POST ['Password'];
$ Query = mysql_query ("insert into tablename1 values ($ id, '$ username',' $ password ')");
If ($ query)
Echo "data inserted successfully ";
Else
Echo "data insertion failed ";
Mysql_close ();
?>