亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

PHP development post comment function tutorial database construction

We need to submit our opinions to the database and save them, and then submit them to the page in real time


Now we create a database named 'comments'

The code is as follows

<?php
//建立'comments'數(shù)據(jù)庫
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 comments";
if (mysqli_query($conn, $sql)) {
    echo "數(shù)據(jù)庫創(chuàng)建成功";
} else {
    echo "數(shù)據(jù)庫創(chuàng)建失敗: " . mysqli_error($conn);
}
mysqli_close($conn);
?>

We are creating a data table named 'comments'

##Field DescriptionidThe commenter’s nicknameComment contentComment time
Field nameid
user
comment
addtime
Field type int
varchar
varchar
datetime
Field Length1130200
The code is as follows
<?php
header("Content-type:text/html;charset=utf-8");    //設(shè)置編碼
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "comments";
// 創(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 `comments` (
  `id` int(11) NOT NULL auto_increment,
  `user` varchar(30) NOT NULL,
  `comment` varchar(200) NOT NULL,
  `addtime` datetime NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM; " ;
if (mysqli_query($conn, $sql)) {
    echo "數(shù)據(jù)表 comments 創(chuàng)建成功";
} else {
    echo "創(chuàng)建數(shù)據(jù)表錯(cuò)誤: " . mysqli_error($conn);
}
mysqli_close($conn);
?>

Create our main page index.html file


Continuing Learning
||
<?php //建立'comments'數(shù)據(jù)庫 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 comments"; if (mysqli_query($conn, $sql)) { echo "數(shù)據(jù)庫創(chuàng)建成功"; } else { echo "數(shù)據(jù)庫創(chuàng)建失敗: " . mysqli_error($conn); } mysqli_close($conn); ?>
submitReset Code