国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Database construction of message board developed by PHP

Message board database construction


#In the previous chapter we completed our page layout. Click to leave a message and something like the picture below will appear. Form

1.jpg

From the picture above, we can see that the name, email address, and message content need to be inserted into the database, but when we look at the message, it usually has a date. , so we also need a date field in the database. Therefore, the fields in our database are as follows

  • Name name

  • Email email

  • Message content content

  • Message date ressage_time


Deposited We can build a database in the fields. This chapter uses PHP code to create a database. The code is as follows

Create a database

<?php
header("Content-type:text/html;charset=utf-8");    //設(shè)置編碼
$servername = "localhost";
$username = "root";
$password = "root";
// 創(chuàng)建連接
$conn = mysqli_connect($servername, $username, $password);
 mysqli_set_charset($conn,'utf8'); //設(shè)定字符集 
// 檢測(cè)連接
if (!$conn) {
    die("連接失敗: " . mysqli_connect_error());
}
// 創(chuàng)建數(shù)據(jù)庫
$sql = "CREATE DATABASE message";
if (mysqli_query($conn, $sql)) {
    echo "數(shù)據(jù)庫創(chuàng)建成功";
} else {
    echo "數(shù)據(jù)庫創(chuàng)建失敗: " . mysqli_error($conn);
}
mysqli_close($conn);
?>

The above code is created A database named message is created. After the database is built, we will create our data table


#Create data table

Table name Ressage_user

Field nameidnameemailcontentressage_timeField typeINTVARCHARVARCHARVARCHARDATEField length63050200##Field Description
<?php
header("Content-type:text/html;charset=utf-8");    //設(shè)置編碼
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "ressage";
// 創(chuàng)建連接
$conn = mysqli_connect($servername, $username, $password, $dbname);
mysqli_set_charset($conn,'utf8'); //設(shè)定字符集 
// 檢測(cè)連接
if (!$conn) {
    die("連接失敗: " . mysqli_connect_error());
}
// 使用 sql 創(chuàng)建數(shù)據(jù)表
$sql = "CREATE TABLE Ressage_user (
 id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
 name VARCHAR(30) NOT NULL,
 email VARCHAR(50) NOT NULL,
 content VARCHAR(200) NOT NULL,
 ressage_time DATE
 );";
if (mysqli_query($conn, $sql)) {
    echo "數(shù)據(jù)表 user 創(chuàng)建成功";
} else {
    echo "創(chuàng)建數(shù)據(jù)表錯(cuò)誤: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
? ? ? ?
? ? ? ?







User The idThe name of the messageThe email address filled in the messageThe content of the messageThe message time
Now that our database is ready, we can store the database in the database. Storing the data requires us to do it on the php page, please continue reading

Continuing Learning
||
<?php header("Content-type:text/html;charset=utf-8"); //設(shè)置編碼 $servername = "localhost"; $username = "root"; $password = "root"; // 創(chuàng)建連接 $conn = mysqli_connect($servername, $username, $password); mysqli_set_charset($conn,'utf8'); //設(shè)定字符集 // 檢測(cè)連接 if (!$conn) { die("連接失敗: " . mysqli_connect_error()); } // 創(chuàng)建數(shù)據(jù)庫 $sql = "CREATE DATABASE message"; if (mysqli_query($conn, $sql)) { echo "數(shù)據(jù)庫創(chuàng)建成功"; } else { echo "數(shù)據(jù)庫創(chuàng)建失敗: " . mysqli_error($conn); } mysqli_close($conn); ?>
submitReset Code