/*
* Vote Example Script
*
* You can see it in action at http://www.lerdorf.on.ca/nameit.php3
* and you can also get the associated image files there.
*
* The MySQL schema that goes along with this is:
* CREATE TABLE names (
* name varchar(30) DEFAULT '' NOT NULL,
* votes int(4),
* PRIMARY KEY (name)
* );
*/
<? if($vote && !$already_voted) SetCookie("already_voted","1");?>
<html><head><title>Name the Baby Computer</title></head>
<body bgcolor="#ffffff" text="#032F5B" link="#537492" vlink="#000000">
<FONT FACE="Verdana, Arial, Helvetica">
<h3>Name the new baby</h3>
I will be getting a cute little <a
href="http://www.corelcomputer.com">NetWinder</a><img src="tm.gif">
box to stick on my LAN at home soon. It needs a name.
<b><i>something</i></b>.lerdorf.on.ca<p>
Please give me some suggestions or vote for an existing one.
</font>
<form action="vote.php3" method="POST">
Suggestion: <input type=text name=new_name size=25 maxlength=29><P>
<input type=submit value="Submit suggestion and/or vote">
<input type=reset><P>
<?
mysql_pconnect("localhost","","");
if($new_name) {
if(!mysql_db_query("rasmus","insert into names values
('$new_name',0)")) {
print mysql_errno().": ".mysql_error()."<BR>";
}
}
if($vote && $already_voted) {
print "<font color=#ff0000>Hey, you voted already! Vote
ignored.</font><P>\n";
}
else if($vote) {
if(!mysql_db_query("rasmus","update names set votes=votes+1 where
name='$vote'")) {
print mysql_errno().": ".mysql_error()."<BR>";
}
}
$result=mysql_db_query("rasmus","select sum(votes) as sum from names");
if($result) {
$sum = (int) mysql_result($result,0,"sum");
mysql_free_result($result);
}