PHP develops simple voting system to create database and table
First create a database "test" in mysql
<?php
// 创建连接
$conn = new mysqli("localhost", "uesename", "password");
// 检测连接
if ($conn->connect_error)
{
die("连接失败: " . $conn->connect_error);}
// 创建数据库
$sql = "CREATE DATABASE test";
if ($conn->query($sql) === TRUE)
{
echo "数据库创建成功";
} else {
echo "Error creating database: " . $conn->error;
}
$conn->close();
?>Then we need to create a voto table to add voting items
Settings The following fields:
#id: It is unique, type is int, and the primary key is selected.
titleid: fixed, type is int
item: voting item, type is varchar, length is 50.
count: Number of votes, type is int.
<?php $SQL = " CREATE TABLE IF NOT EXISTS `voto` ( `id` int(10) NOT NULL auto_increment, `titleid` int(10) default NULL, `item` varchar(50) default NULL, `count` int(10) default NULL, PRIMARY KEY (`id`) )ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8;" ?>
Add some test content, such as
<?php
$SQL = "INSERT INTO vote VALUES ('24', '1', '张学友', '8');"
$SQL = "INSERT INTO vote VALUES ('25', '1', '陈奕迅', '12');"
$SQL = "INSERT INTO vote VALUES ('26', '1', '林俊杰', '12');"
$SQL = "INSERT INTO vote VALUES ('27', '1', '萧敬腾', '23');"
?>and then create another table votetitle to store the title.
Set the following fields:
titleid: type is int
votetitle: title, type is varchar, length is 50.
<?php $SQL = " CREATE TABLE IF NOT EXISTS `votetitle` ( `titleid` int(10) NOT NULL, `votetitle` varchar(50) default NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ?>
Add a title statement:
<?php
$SQL = "INSERT INTO votetitle VALUES ('1', '您认为本网站还有那些要做调整?');"
?>In this way, we have created the database and tables, and added some test data.
- Course Recommendations
- Courseware download
The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~ 















