Create online polls with PHP and MySQL : Tutorial
Want to find out what people think? An online poll lets people interact with your site and we’re going to show you how to record their votes and display the results.
Not every Web page stays the same. Think of an online store, bank or forum and you’ll see that the same page can be many things to many people. But how is it done? Most professional Web hosts provide Linux, the Apache Web server, the MySQL database and the PHP scripting language. Together, ‘LAMP’ lets you create ‘dynamic’ Web pages, pages where the HTML depends upon cookies, forms and other data sources. In this example – an online poll on the best Mac hardware – we’re
1: Log on to MySQL
Using CocoaMySQL (available for free from http://cocoamysql.sourceforge.net), log onto your MySQL server. You’ll need the URL, your ID and your password.
2: Create a database
If you don’t have a database provided for you by your ISP, you’ll need to create one by clicking on the ‘Create Database’ button. We’ll call ours ‘poll’.
3: Create a table
Databases store their information in ‘tables’. You can have more than one table in a database. Click on ‘Create Table’ and create a table called ‘results’.
4: Create a field
Every table stores data in ‘rows’. Each row has ‘fields’ to store specific facts in each row. Click on ‘Create Field’ and create a field called ’answer’, of type ‘text’.
5: A change of name
Start Dreamweaver. To use PHP tags, an HTML file needs a ‘.php’ extension. So rename ‘index.html’ to ‘index.php’ and let Dreamweaver alter the site links.
6: For form’s sake
We’re going to set up all possible variants of the homepage now. We need a voting form first, so add one with method ‘POST’ and action ‘index.php’.
0 Comments:
Post a Comment