I have this voting thing (The medal voting for all who already know) that I'm doing. (taking forever because I'm learning). But, anyway...
I have a loop that makes Radio Buttons. With "Yes" & "No" buttons on each. For each Thing to vote for...
(I took out unneeded info)
PHP:
--------------------------------------------------------------------------------
<?php
$all_votes_sql = "SELECT voter, original, originator, poll_end, member, medal FROM votes WHERE original > '0'";
$all_votes_result = mysql_query($all_votes_sql);
if(mysql_error())
{
die("There Was An Error Loading The Current Polls List");
}
else{
$num=0;
while($row = mysql_fetch_array($all_votes_result))
{
$num++;
echo '<td bgcolor="#e1e1e1">';
echo '<input type="hidden" name="voter_sub_'.$num.'" value="' . $username . '">';
echo '<input type="hidden" name="member_sub_'.$num.'" value="' . $row[member] . '">';
echo '<input type="hidden" name="medal_sub_'.$num.'" value="' . $row[medal] . '">';
echo '<input type="radio" NAME="vote_sub_'.$num.'" VALUE="1" class="textinput">Yes<br />';
echo '<input type="radio" NAME="vote_sub_'.$num.'" VALUE="0" class="textinput">No</td>';
$button = true;
}
}
?>
--------------------------------------------------------------------------------
Anyway...
I tried to loop it with each input type having a different "id number". If you noticed so you can identify each seperate vote (I hope that is the right way). Anyway, the page reloads and I need a script that can Identify each vote and put the stuff needed for each inside the "votes" table.
This is what I attempted to do...
Do I need to loop the REQUEST, the MySQL, and the submission and stuff?
I didn't bother, because I never did it and don't know what to loop.
[php]
<?
if ($REQUEST_METHOD == 'POST') {
$voter_sub = $_REQUEST['voter_sub'] ;
$member_sub = $_REQUEST['member_sub'] ;
$medal_sub = $_REQUEST['medal_sub'] ;
$vote_sub = $_REQUEST['vote_sub'] ;
if(isset($voter_sub) and isset($member_sub) and isset($medal_sub) and isset($vote_sub) and empty($the_voter) and empty($voted_member) and empty($voted_medal))
{
$check_voter_sql = "SELECT voter, member, medal FROM votes WHERE member='$member_sub' and medal='$medal_sub'";
$check_voter_sql_queried = mysql_query($check_voter_sql);
$check_voter_data_array = mysql_fetch_array($check_voter_sql_queried);
if (mysql_error()) {
print('There Was An Error Submitting Your Vote');
}
else{
if($check_voter_data_array[voter] == $voter_sub){
print('You already voted for this one.');
}
else
{
$create_vote_sql = "INSERT INTO votes (original, voter, member, medal, vote) VALUES('0', '$voter_sub', '$member_sub', '$medal_sub', '$vote_sub')";
mysql_query($create_vote_sql);
}
}
}
else
{
header( "Location: error.html" );
}
}
}
?>
I have a loop that makes Radio Buttons. With "Yes" & "No" buttons on each. For each Thing to vote for...
(I took out unneeded info)
PHP:
--------------------------------------------------------------------------------
<?php
$all_votes_sql = "SELECT voter, original, originator, poll_end, member, medal FROM votes WHERE original > '0'";
$all_votes_result = mysql_query($all_votes_sql);
if(mysql_error())
{
die("There Was An Error Loading The Current Polls List");
}
else{
$num=0;
while($row = mysql_fetch_array($all_votes_result))
{
$num++;
echo '<td bgcolor="#e1e1e1">';
echo '<input type="hidden" name="voter_sub_'.$num.'" value="' . $username . '">';
echo '<input type="hidden" name="member_sub_'.$num.'" value="' . $row[member] . '">';
echo '<input type="hidden" name="medal_sub_'.$num.'" value="' . $row[medal] . '">';
echo '<input type="radio" NAME="vote_sub_'.$num.'" VALUE="1" class="textinput">Yes<br />';
echo '<input type="radio" NAME="vote_sub_'.$num.'" VALUE="0" class="textinput">No</td>';
$button = true;
}
}
?>
--------------------------------------------------------------------------------
Anyway...
I tried to loop it with each input type having a different "id number". If you noticed so you can identify each seperate vote (I hope that is the right way). Anyway, the page reloads and I need a script that can Identify each vote and put the stuff needed for each inside the "votes" table.
This is what I attempted to do...
Do I need to loop the REQUEST, the MySQL, and the submission and stuff?
I didn't bother, because I never did it and don't know what to loop.
[php]
<?
if ($REQUEST_METHOD == 'POST') {
$voter_sub = $_REQUEST['voter_sub'] ;
$member_sub = $_REQUEST['member_sub'] ;
$medal_sub = $_REQUEST['medal_sub'] ;
$vote_sub = $_REQUEST['vote_sub'] ;
if(isset($voter_sub) and isset($member_sub) and isset($medal_sub) and isset($vote_sub) and empty($the_voter) and empty($voted_member) and empty($voted_medal))
{
$check_voter_sql = "SELECT voter, member, medal FROM votes WHERE member='$member_sub' and medal='$medal_sub'";
$check_voter_sql_queried = mysql_query($check_voter_sql);
$check_voter_data_array = mysql_fetch_array($check_voter_sql_queried);
if (mysql_error()) {
print('There Was An Error Submitting Your Vote');
}
else{
if($check_voter_data_array[voter] == $voter_sub){
print('You already voted for this one.');
}
else
{
$create_vote_sql = "INSERT INTO votes (original, voter, member, medal, vote) VALUES('0', '$voter_sub', '$member_sub', '$medal_sub', '$vote_sub')";
mysql_query($create_vote_sql);
}
}
}
else
{
header( "Location: error.html" );
}
}
}
?>
Comment