Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 06-21-2006, 09:28 PM A Simple_Poll
Junior Talker

Posts: 1
Name: Fred
Trades: 0
OS:Xp, PHP4, NoDB
Objective: A Simple Poll that will keep numeric track of students who like school and who don't like school.

I am having 2 problems. The 1st problem: The program is allowing the user to choose both Yes and No questions. I thought with radio buttons only 1 choice can be made?

The 2nd problem is that I am unable to keep track of the poll using the $YES and $NO variables.

Here is the form:
<h1><center>Here Is A Simple Poll</center></h1>

<br /><h3>Do you like school?</h3>

<FORM METHOD = "POST" ACTION = "poll_results.php"
<br /><INPUT TYPE = "RADIO" NAME = "YES" VALUE = "ido"> YES
<br /><INPUT TYPE = "RADIO" NAME = "NO" VALUE = "idonot"> NO

<br /><INPUT TYPE = "SUBMIT" VALUE = "Send Your Vote">
</FORM>

Here is the PHP Script:
<?
$Yes = 0;
$NO = 0;
if ($_POST["YES"])
{
$Yes++;
echo "<br>I am glad you like school";
echo $Yes;
}
else ($_POST["NO"])
{
$NO++;
echo "<br>I am sorry you don't like school";
echo $NO;
}
?>
Nerd_energy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-21-2006, 10:31 PM Re: A Simple_Poll
Skorch1's Avatar
Super Talker

Posts: 115
Location: California
Trades: 0
The first problem I see is that only 1 person at a time can like or dislike school. Your $Yes and $NO variables are both set to zero when the page is loaded. Only one of them is incremented and then the information is not saved. That means when the next person votes in your poll $Yes and $NO will be once again set to 0 and only one of them will be incremented . You must save the value in a database of some sort and retrieve it from the database.

Your second problem is that you have two radio buttons with DIFFERENT names. You must name them the same thing so only 1 option can be selected.
Code:
Wrong

<br /><INPUT TYPE = "RADIO" NAME = "YES" VALUE = "ido"> YES
<br /><INPUT TYPE = "RADIO" NAME = "NO" VALUE = "idonot"> NO

Right

<br /><INPUT TYPE = "RADIO" NAME = "school" VALUE = "ido"> YES
<br /><INPUT TYPE = "RADIO" NAME = "school" VALUE = "idonot"> NO
__________________
Check out my
Please login or register to view this content. Registration is FREE
website!
Skorch1 is offline
Reply With Quote
View Public Profile Visit Skorch1's homepage!
 
Old 06-21-2006, 10:32 PM Re: A Simple_Poll
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
The way for a radio button to work with only allowing either one or the other option to to assign then the same input name. The values are what is used to determine the choice selected.

Code:
<input type="radio" name="school" value="yes" /><br />
<input type="radio" name="school" value="no" /><br />
With the php, you should check if the post form value is set, and then evaluate one or default to the other according to selection. Also you were assigning a value of "0" to both vars $YES and $NO and then increasing the amount to "1". If you want to store the values in a flat text file instead of a database, first you would need to read the current values of each and then increment that number.

PHP Code:
<?php
  
  $YES 
''// Value from text file
  
$NO  ''// Value from text file
  
  
if (isset($_POST['school'])) {
    
    if (
$_POST['school'] == 'yes') {
      
      
$YES++;
      echo 
'<br />I am glad you like school ' $YES;
      
    } else {
      
      
$NO++;
      echo 
'<br />I am sorry you don\'t like school ' $NO;
    }
  }
  
?>
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 06-22-2006, 05:40 AM Re: A Simple_Poll
Novice Talker

Posts: 5
Trades: 0
hey friend,
that's what u wrote, but it's wrong:

<br /><INPUT TYPE = "RADIO" NAME = "YES" VALUE = "ido"> YES
<br /><INPUT TYPE = "RADIO" NAME = "NO" VALUE = "idonot"> NO

in fact what u need to write is that:

<br /><INPUT TYPE = "RADIO" NAME = "TEST" VALUE = "ido"> YES
<br /><INPUT TYPE = "RADIO" NAME = "TEST" VALUE = "idonot"> NO

both radio have the same name
pitas is offline
Reply With Quote
View Public Profile
 
Old 06-22-2006, 08:43 AM Re: A Simple_Poll
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
Well I personally would go for a simpler way

<INPUT TYPE = "RADIO" NAME = "YES" VALUE = "ido">
<INPUT TYPE = "RADIO" NAME = "NO" VALUE = "idonot">
should be

<INPUT TYPE = "RADIO" NAME = "poll" VALUE = "1">
<INPUT TYPE = "RADIO" NAME = "poll" VALUE = "0">

Then you can quite easily keep counting this by

switch($_GET['poll']){
case 1:
$sql = "update poll set yes=yes+1";
break;
case 0:
$sql = "update poll set no=no+1";
break;
}

This now allows you to retrive a simple value for yes and no and you can easily build a graph upon these yes and no values.

Ibbo
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 08-19-2006, 01:45 PM Re: A Simple_Poll
Average Talker

Posts: 16
Name: Pavel Reich
Trades: 0
May be you need online poll builder?
You can see it here Online Survey Research..

If you want to develop vote script, you need some storage like a text file or database (mysql). If you will use text file, don't forget to use file locking mechanizm
__________________
--

Please login or register to view this content. Registration is FREE
- Your website monitoring.

Please login or register to view this content. Registration is FREE
- free website hosting for your domain
pinger is offline
Reply With Quote
View Public Profile Visit pinger's homepage!
 
Reply     « Reply to A Simple_Poll
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.32868 seconds with 12 queries