Display page (user visible)
<body>
<form action= "chuli.php" method= "POST" >//Data received from this page to the Chuli page for processing
<div> Nationality Code: <input type= "text" name= "code"/></div>//Create a div and put in the receiver to receive the code value
<div> Nationality Name: <input type= "text" name= "name"/></div>//Create a div and put in the receiver to receive the name value
<input type= "Submit" value= "Submission"/>
</form>
</body>
Action page (user not visible)
<?php//Processing page just keep the PHP code
$code = $_post["code"]; Set a variable to receive user-submitted code values
$name = $_post["name"]; Set a variable to receive the user-submitted name value
Build connection
$conn = @mysql_connect ("localhost", "root", "123"); LocalHost is the native server address, root is the user name, and 123 is the database password
Select the Operational database
mysql_select_db ("< database name >", $conn);
Write SQL statements
$sql = "INSERT into Nation values ('{$code}','{$name} ') "; Add data to the database, if it is an integer number or a Boolean type cannot be enclosed in single quotes, use only the Vachar type to enclose the single quotation mark
Perform
$result = mysql_query ($sql);
if ($result)//Create a conditional statement to remind the programmer whether the data was added successfully
{
Jump page
Header ("location:lizi.php"); Add success, then jump back to Lizi page, that is, user input page
}
Else
{
echo "Add failed! "; Add failed to display prompt message, add failed
}
Using PHP to add data to the database