Re: PHP Code

  • From: Jared Wright <wright.jaredm@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Fri, 19 Aug 2011 02:14:39 -0400

Yep, he just seemed like he was just getting started, so I thought a more straightforward database model might be a little easier to get his feet wet with. This would be the more sustainable and flexible model in the long term.

On 8/19/2011 1:46 AM, black ares wrote:
Uau!
What normalised data table!:)
I will do it like this:
1. A table with polid and question_text
2. a table with answerid, polid, answer text, no_votes

So, the code must take out the answers for a specified id from the answer table. And when some one votes it will simply increment the answer table no_Votes field for the specified answer.

The advantage of this aproach is that you can have no limit to the answers per poll.



----- Original Message ----- From: "Jared Wright" <wright.jaredm@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Friday, August 19, 2011 6:02 AM
Subject: Re: PHP Code


Sorry. WE, um, got a little distracted from actual programming. Something about search engine interfaces, I think. *grin*

I think your more immediate concern is your database model itself. You need to have the number of votes for each answer in there somewhere. There are a few ways you could construct this in the database, the most basic being a polls table that contains a PollID (the primary key), a question, five answer fields, and five total vote fields. At its most basic, all voteprocessing.php needs to do is increment the value of the total votes field that matches the voter's answer. Then retrieve all the answers and total votes from the Polls table and output them. Let's forget about archiving voter's ansewrs for now until we get this ironed out.
On 8/18/2011 7:18 PM, Edgar Lozano wrote:
Wow! Haven't gotten a reply. Anyway, I still need some assistance with
this PHP code.

On 8/3/11, Jacob Kruger<jacobk@xxxxxxxxxxxxxx>  wrote:
Ok, will try have a look at it a bit later, and let you know, but, FWIW, I
only sort of play around in PHP currently, but anyway.

Stay well

Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'

----- Original Message -----
From: "Edgar Lozano"<1419goku@xxxxxxxxx>
To:<programmingblind@xxxxxxxxxxxxx>
Sent: Wednesday, August 03, 2011 6:01 PM
Subject: Re: PHP Code


I don't get any errors yet. But what I'm asking, is if anyone could
direct me in the right path to complete this little voting page.
That's all.
Thanks

On 8/3/11, jacobk@xxxxxxxxxxxxxx<jacobk@xxxxxxxxxxxxxx>  wrote:
Ok, what is the actual error you get when you try use these pages then?

Stay well

Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'
On Tue, 2 Aug 2011 16:18:07 -0500, Edgar Lozano<1419goku@xxxxxxxxx>
wrote:
I'm sorry. The config.php file is config.inc. It works the same for
me. Anyway, thanks for pointing that out!

On 8/2/11, Jacob Kruger<jacobk@xxxxxxxxxxxxxx>  wrote:
Off hand, you said the first file is config.php, but in vote.php,
you're
telling it to include config.inc...?

Stay well

Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'

----- Original Message -----
From: "Edgar Lozano"<1419goku@xxxxxxxxx>
To:<programmingblind@xxxxxxxxxxxxx>
Sent: Tuesday, August 02, 2011 8:28 PM
Subject: PHP Code


Hello all.
Hope yall don't mind me throwing some PHP code out there. Could you
please give me some suggestions?
I'm trying to create a voting page for my website. The files are as
follows:
A config.php file
An index.php file,
An vote.php file
And a voteprocessing.php file.
The contents of the config.php file are as follows:
<?php
$host="localhost";
$user="user";
$pass="password";
$edgar=mysql_connect($host,$user,$pass);
if(!$edgar)
{
die("Cannot connect properly. " . mysql_error());
}
$db="database2";
$db2=mysql_select_db($db,$edgar);
if(!$db2)
{
die("Error: cannot find Database. " . mysql_error());
}
The contents of the Index.php file are as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd";>
<html lang="en-US">
<head>
<title>Voting page</title>
</head>
<body>
<div id="main">
<p>
Hello. Welcome to my voting page.<br>
On this page, you are allowed to vote on your favorite music!<br>
Everyday, I have a song of the day, and I would like more interaction
for that section.<br>
I can't come up with any ideas of music that other people will like,
so everyday, I will put options for you to vote on.<br>
</p>
<p>
Rules<br><br>
In order for you to vote, you will need to have an account on my
Forum!<br>
To log into my forum,
<a href="http://edgar.ueuo.com/forum/login.php";>Click Here.</a><br> If you would like to register, to take advantage of all these cool
things, you can register
<a href="http://edgar.ueuo.com/forum/register.php";>Here.</a><br>
Finally, if you want to vote,
<a href="http://edgar.ueuo.com/music/vote.php";>Click Here.</a><br>
Thank you for your interest, and participation in my website.
</p>
</div>
&copy by Edgar Lozano<br>
All Rights Reserved
</body>
</html>
The contents of the vote.php file are as follows:
<?php
include("config.inc");
$question = "What would you like the song of the day to be for
tomorrow?";
$a1 = "A wrap song";
$a2 = "A Country Song";
$a3 = "Another genre";
$a4 = "Random song";
$a5 = "I cannot decide give me more options";
$insert = "INSERT INTO Polls
VALUES('', '$question', '$a1', '$a2', '$a3', '$a4', '$a5')";
if(!mysql_query($insert))
{
die("Error: " . mysql_error());
}
?>
<html>
<head>
<title>Song of The Day Voting Page</title>
</head>
<body>
<p>To vote, just select your option, and click on the submit
button.</p>
<?php
echo $question . "<br>";
?>
<form action="voteprocessing.php" method="post">
<?php echo $a1 . "<br>"; ?> <input type="radio" name="answer1"/>
<?php echo $a2 . "<br>"; ?> <input type="radio" name="answer2"/>
<?php echo $a3 . "<br>"; ?> <input type="radio" name="answer3"/>
<?php echo $a4 . "<br>"; ?> <input type="radio" name="answer4"/>
<?php echo $a5 . "<br>"; ?> <input type="radio" name="answer5"/>
<input type="submit" name="submit" value="vote"/>
</form>
</body>
</html>
And finally, the contents of the voteprocessing.php file are as
follows:
<?php
include("config.inc");
echo "Thanks for voting.";
echo "The results are as follows!";
$answer1 = $_post['answer1'];
$answer2 = $_post['answer2'];
$answer3 = $_post['answer3'];
$answer4 = $_post['answer4'];
$answer5 = $_post['answer5'];
$submit = $_post['submit'];
$sql = mysql_query("insert into pollAnswers
(pk_id, pollID, answer, visitorIP)
values('', '', '$submit', '')");
if(!$sql)
{
die("error: " . mysql_error());
}
?>
As you can see, I have already created two tables. pollAnswers and polls. I want Polls to contain the poll question and the five answers to that question. I want the PollAnswers table to contain the pollID and pk_id with the visitors IP address and the answer that they chose. Can someone direct me in the right path to how to construct the rest
of this voteprocessing.php file?
I would greatly appreciate it!
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: