search
  • Sign In
  • Sign Up
Password reset successful

Follow the proiects vou are interested in andi aet the latestnews about them taster

PHP development message board tutorial database

Database creation

The code below creates a database named "message"

Character encoding is "utf8"

<?php
header("Content-type:text/html;charset=utf-8");    //设置编码
$servername = "localhost";
$username = "root";
$password = "root";
// 创建连接
$conn = mysqli_connect($servername, $username, $password);
 mysqli_set_charset($conn,'utf8'); //设定字符集 
// 检测连接
if (!$conn) {
    die("连接失败: " . mysqli_connect_error());
}
// 创建数据库
$sql = "CREATE DATABASE message";
if (mysqli_query($conn, $sql)) {
    echo "数据库创建成功";
} else {
    echo "数据库创建失败: " . mysqli_error($conn);
}
mysqli_close($conn);
?>

Data table creation

The following code creates the name It is the data table of 'Ressage_user'. The fields are as follows

##Field nameidnameemailcontentressage_timeField typeINTVARCHARVARCHARVARCHARDATEField length63050200##Field Description
<?php
header("Content-type:text/html;charset=utf-8");    //设置编码
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "ressage";
// 创建连接
$conn = mysqli_connect($servername, $username, $password, $dbname);
mysqli_set_charset($conn,'utf8'); //设定字符集 
// 检测连接
if (!$conn) {
    die("连接失败: " . mysqli_connect_error());
}
// 使用 sql 创建数据表
$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 "数据表 user 创建成功";
} else {
    echo "创建数据表错误: " . 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

new file
<?php header("Content-type:text/html;charset=utf-8"); //设置编码 $servername = "localhost"; $username = "root"; $password = "root"; // 创建连接 $conn = mysqli_connect($servername, $username, $password); mysqli_set_charset($conn,'utf8'); //设定字符集 // 检测连接 if (!$conn) { die("连接失败: " . mysqli_connect_error()); } // 创建数据库 $sql = "CREATE DATABASE message"; if (mysqli_query($conn, $sql)) { echo "数据库创建成功"; } else { echo "数据库创建失败: " . mysqli_error($conn); } mysqli_close($conn); ?>
Reset Code
Automatic operation
submit
Preview Clear