Tell us what you look for in a web host!
|
|
PHP MySQL Interactive Website Design
Create a Simple Poll
PHP and MySQL make creating interactive websites easier than ever before. Here is a simple form and processing script which you can modify and use to poll your visitors. The form on the left is a modified version.
Create the database through your PHPMySQL Admin Panel or modify the birthday scripts to create a table with the 3 fields: color, code and number
This PHP script can be used to parse forms that use checkboxes for multiple selections like the one on the left. A sample form using radio buttons is provided below.
The bolded portion of the code loops through your user's selections, if there are more than one, and adds 1 to the selected field.
<?php
$db="mydatabase";
$link = mysql_connect("localhost");
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link) or die("Couldn't open $db: ".mysql_error());
/*loop through the selected fields - multiple if using checkbox*/
foreach ($check as $value){
mysql_query("UPDATE simplepoll SET number=number+1 WHERE code LIKE '$value'");
}
//select the new updated values
$result = mysql_query( "SELECT color,number FROM simplepoll" ) or die("SELECT Error: ".mysql_error());
//display the updated results
$num_rows = mysql_num_rows($result);
print "<html><head><style type=text/css>
#poll{border-top :solid #004f9d 2px;border-left :solid #004f9d 2px} #poll tr td {border-bottom :solid #004f9d 2px;border-right :solid #004f9d 2px} #poll tr td {font-family: Small Fonts;font-style : normal ;font-size : 7pt; font-weight :bold } h3{font-family: Arial;font-style : normal ;font-size : 9pt; font-weight :bold;text-align : center; color :#FFFFFF;background-color :#004f9d }</style>
</head>
<body>
<table width=100%><tr valign=top><td>\n";
print "<table ID=poll cellspacing=0 cellpadding=5 width=125 >\n";
print "<tr valign=top><td colspan=2 bgcolor=#004f9d><h3>Other users chose these options.</h3></td></tr>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field )
print "\t<td>$field</td>\n";
print "</tr>\n";
}
print "</table>
</tr></table></body></html>\n";
mysql_close($link);
?>
|
Contents
Free PHP MySQL Tools
Introduction to PHP MySQL
Connecting to the Server
Creating a Database
Create a Table
Adding Data
Displaying Data
Editing Table Data
Altering Tables
Advanced
Multiple Selection Forms
|