Let's analyze the process first.
One, database tutorial,
Second, database file dbconn.php
Three, vote.php voting page
Four, voting function page vote_add.php
Five, view all voting data viewpoll.php
Now let's look at the database structure.
The code is as follows |
Copy Code |
Drop database if exists vote; Create database vote; Use vote; CREATE table title ( ID INT (6) not NULL auto_increment, Username varchar is not NULL, Email varchar not NULL, title varchar () not NULL default ', Types tinyint (2) Not NULL default ' 1 ', Choice text, times datetime not NULL default ' 0000-00-00 00:00:00 ', Primary KEY (ID) ); CREATE table vote ( id Int (6) not NULL auto_increment, titleid Int (6) Not NULL default ' 0 ', & nbsp; info Text Not null, vcount Int (4) Not NULL default ' 0 ', primary KEY (ID) ); CREATE TABLE Email ( ID INT (6) NOT NULL, Email varchar NOT NULL, Primary key (ID, email) ); |
Database connection files
The code is as follows |
Copy Code |
<?php $conn =mysql_connect ("localhost", "phpdb", "phpdb") Or Die ("Cannot connect to the database server:". mysql_error ()); mysql_select_db ("vote", $conn) or Die ("Cannot select Database:". mysql_error ()); ?> |