Database:
CREATE DATABASE
Create Database Note10 charset UTF8;
using database
use Note10;
Set names GBK;
CREATE TABLE
Creation Table Show_register (
ID int auto_increment primary key,
username varchar (+) Unique not null,< br> Password char (+) NOT NULL,
age tinyint unsigned,
edu enum (' Primary ', ' Junior ', ' High school ', ' undergraduate ', ' Graduate ', ' PhD '),
insterest set (' Volleyball ', ' basketball ', ' football ', ' Chinese football ', ' tennis '),
Address enum (' Northeast ', ' North ', ' Northwest ', ' East China ', ' South China ', ' Huaxi '),
regtime datetime
);
PHP Files:
<?php
//2,
mysql_connect ("localhost", ' root ', ' 123456 ');
Mysql_set_charset ("UTF8"); You can also use mysql_query ("Set names UTF8");
$sql = "Use Note10;";
mysql_query ($sql);
if ($_post) {
$username =$_post[' username '];
$password =$_post[' password '];
$age =$_post[' age ';
$edu =$_post[' edu '];
$insterest =$_post[' insterest '];
$address =$_post[' address ';
if (Empty ($username) | | empty ($password)) {
$result 1 = "The user name or password entered is empty";
}else{
//Because the field is set in the database as a set () type, the value passed is a function type
For example: Database fields: Enum (' Primary ', ' Junior ', ' High school ', ' undergraduate ', ' Graduate ', ' PhD ')
The subscript and value of the array are: 2 of 0, 2 of 1, 2 2.
The numbers in the computed array correspond to the fields, so the sum
$insterestSum =array_sum ($insterest);
$sql = "INSERT into Show_register (username,password,age,edu,insterest,address,regtime) values";
$sql. = "(' $username ', ' $password ', ' $age ', ' $edu ', ' $insterestSum ', ' $address ', Now ())";
$result =mysql_query ($sql);
if ($result = = = "false") {
$result 1 = "Insert data Failed". Mysql_error ();
}else{
$result 1 = "Add Success";
}
}
}
?>
5.3
<?php
if ($_get) {
if (!empty ($_get[' ID ')) {
$id = $_get[' id '];
$sql = "Delete from Show_register where id= $id";
$result = mysql_query ($sql);
if ($result = = = False) {
$ERRMSG = "Execution failed, please refer to:". Mysql_error ();
}
else{
$ERRMSG = "Delete succeeded. ";
}
}
}
?>
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8"/>
<body>
3.
<div>
<?php
if (!empty ($result 1)) {
echo $result 1;
}
?>
</div>
1.
<form action= "" method= "POST" >
User name: <input type= "text" name= "username" ><br/>
Password: <input type= "password" name= "password" ><br/>
Age: <input type= "text" Name= "ages" ><br/>
Education: <select name= "edu" >
<option value= "1" > Primary </option>
<option value= "2" > Junior </option>
<option value= "3" > High school </option>
<option value= "4" > Undergraduate </option>
<option value= "5" > Postgraduate </option>
<option value= "6" > PhD </option>
</select><br/>
Interests: <input type= "checkbox" Name= "insterest[]" value= "1" > Volleyball
<input type= "checkbox" Name= "insterest[]" value= "2" > Basketball
<input type= "checkbox" Name= "insterest[]" value= "4" > Soccer
<input type= "checkbox" Name= "insterest[]" value= "8" > Chinese football
<input type= "checkbox" Name= "insterest[" "value=" > Tennis <br/>
From: <input type= "Radio" name= "Address" value= "1" > Tohoku
<input type= "Radio" name= "Address" value= "2" > North China
<input type= "Radio" name= "Address" value= "3" > NW
<input type= "Radio" name= "Address" value= "4" > East China
<input type= "Radio" name= "Address" value= "5" > South China
<input type= "Radio" name= "Address" value= "6" > Huaxi <br/>
<input type= "Submit" value= "Submission" >
</form>
</body>
4.
<?php
6.1
$pageSize = 2; Control the number of displays per page
$page = 1; The first default is page 1th
if (!empty ($_get[' page ')) {
$page = $_get[' page '];
}
$start = ($page-1) * $pageSize; Start line number
$sql = "SELECT * from Show_register ORDER BY id desc limit $start, $pageSize ; ";
$result =mysql_query ($sql);
if ($result ===false) {
echo "Failed to get data";
}else{
$fileName = $_ server[' Script_name ']; 5.1 6.2 Gets the current relative path/folder/file name. PHP form
$numCount =mysql_num_fields ($result); // Gets the number of fields in the result set
echo "<table border= ' 2 ' >";
echo "<tr>";
echo "<th>ID</th>". " <th> user name </th> "." <th> password </th> "." <th> age </th> "." <th> education </th> "." <th> interests </th> "." <th> from </th> "." <th> registration Time </th> "." <th> Operation </th> ";
echo "</tr>";
while ($arr =mysql_fetch_array ($result)) {//Gets a row from the result set as an associative array
echo "<tr>";
for ($i =0; $i < $numCount; $i + +) {
$fieldName =mysql_field_name ($result, $i); The first name of the I field taken from the result set (I count from 0)
echo "<td>". $arr [$fieldName]. " </td> ";
}
$fileName = $_server[' script_name ');
echo "<td>";
echo "[<a href= ' $fileName? id={$arr [' ID ']} ' > Delete </a>]; 5.2
echo "</td>";
echo "</tr>";
}
echo "</table>";
6.3
for ($i = 1; $i <=; + + $i) {
$fileName = $_server[' script_name ');
echo "<a href= ' $fileName? page= $i ' > $i </a>";
}
}
?>
<!--notes
<?php
$sql = "SELECT * from Show_register";
$result =mysql_query ($sql);
if ($result ===false) {
echo "Failed to get data";
}else{
$numCount =mysql_num_fields ($result); Get the number of fields in the result set
echo "<table border= ' 2 ' >";
echo "<tr>";
echo "<th>ID</th>". " <th> user name </th> "." <th> password </th> "." <th> age </th> "." <th> education </th> "." <th> interests </th> "." <th> from </th> "." <th> registration Time </th> "." <th> Operation </th> ";
echo "</tr>";
while ($arr =mysql_fetch_array ($result)) {//Gets a row from the result set as an associative array
echo "<tr>";
for ($i =0; $i < $numCount; $i + +) {
$fieldName =mysql_field_name ($result, $i); The first name of the I field taken from the result set (I count from 0)
echo "<td>". $arr [$fieldName]. " </td> ";
}
$fileName = $_server[' script_name ');
echo "<td>";
echo "[<a href= ' $fileName? id={$arr [' ID ']} ' > Delete </a>];
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
?>
Comment-
1, Display data table, delete data--database manipulation, simple paging