hi,

im making a website for my final year project, and im having some trouble. im making a voting site that uses the single transferable vote method. im new to php as well.
basically, im having trouble handling radio buttons made in another script. the problem i have is that i've set the name of each set of radion button as the name of the candidate, and this is done by using a for loop and an array( ass you can see in the code below)

echo '<form action="registervote.php" method="post">';
echo '<table align="center" cellspacing="50" cellpadding="5" border="2">';
echo '<tr>';
for($i=1; $i<=$num; $i++)
{
    $arr1=mysql_fetch_array($result, MYSQL_ASSOC);
    echo '<th align="center" bgcolor="yellow">' . $arr1['name'] . '</th>';

while(!$i)
{
   echo '</tr><tr>';
}

for($j=0; $j<=$num; $j++)
   {
  echo '<td align="center">'.($j+1).'<input type="radio" name="'.$arr1['name'].'" value="'($j+1).'"/></td>';
   }
  echo '</tr>';
   }

echo '</table>';

echo '<p><br /><center/><input type="submit" name="submit" value="VOTE!" /></p>';
echo '<input type="hidden" name="submitted" value="TRUE" />';

the handling script is below, what i need it to do is to confirm that an input has been selected(then i can add the input value into my MySQL database table):

if(isset($_POST['submitted']))
{

if(isset($_POST['']))
{
    echo '<p>input has been selected</p>';
}
else
    {
        echo 'no input';
    }

} 

what i haven't been able to figure out for two days is what i should write in the $_POST[] array to handle the radio button. all the radio buttons would have their names set as the candidate name in the ballot that they would be taking part in. so i cant just set each set of radio buttons' name as the name of each candidate manually, as these can change for each ballot. i dont know how to check if the name of the radio button(which is an array) has been set, using the isset() function. please help.

    radio button are supposed to be named with a common name but a different value e.g.

    <form name = 'myvoteform' action = 'someprocess.php' method = 'post'>
    <input type = 'radio' name ='candidate' value = 'democrat' />Democrat<br />
    <input type = 'radio' name ='candidate' value  = 'republican' />Republican<br />
    <input type = 'radio' name ='candidate' value = 'independant' />Independant<br />
    <input type = 'submit' value = 'Vote' />
    </form>

    Now you would have to amend your database so that you have fields for democrats, republicans, independants, and possibly other off the wall parties like the Green Party or the Marijuana Party or the Communist Party.

    Checkeboxs on the other hand should be an array since zero all or any number between zero and all can be selected. and would be written in the form as

    <input type = 'checkbox' name = 'foods[]' value = 'chicken' />Chicken<br />
    <input type = 'checkbox' name = 'foods[]' value = 'beef' />Beef<br />
    <input type = 'checkbox' name = 'foods[]' value = 'pork' />Pork<br />
    

    Or if you wanted to use an associative array then use

    <input type = 'checkbox' name = 'foods[chicken]' value = 'chicken' />Chicken<br />
    <input type = 'checkbox' name = 'foods[beef]' value = 'beef' />Beef<br />
    <input type = 'checkbox' name = 'foods[pork]' value = 'pork' />Pork<br />

      thank you for your reply houdini,

      sorry i didnt make my question clearer. basically, i have a few candidates in a ballot. so each candidate will have his own group of radio buttons. the name of each candidate's group will be set as his/her name but the values will be different as you can see below and in the html source i've also included.

      <input type="radio" name="Wayne Rooney" value="1"/>
      <input type="radio" name="Wayne Rooney" value="2"/>
      <input type="radio" name="Wayne Rooney" value="3"/>
      <input type="radio" name="Wayne Rooney" value="4"/>

      the voter will select a number(for this example, 1 to 4). so what im having trouble with is what to write in the $_POST, so that the script checks which candidate's radio button has been selected.
      i can't manually set the name of each candidate because each ballot will have different candidates, so the names would be different and thats the reason i have set the name of each candidate in the for loop as:

      name="'.$arr1['name'].'"

      $arr1 is defined as:

      $arr1=mysql_fetch_array($result, MYSQL_ASSOC);

      so the name of each radio button will be the name of each candidate because $result is set thus:

      $query="SELECT CONCAT(candidate_Fname, ' ', candidate_Sname) AS name FROM candidates";
      $result=@mysql_query($query);

      also $num is:

      $num=mysql_num_rows($result);

      below is the html source for the page:

      <form action="registervote.php" method="post"><table align="center" cellspacing="50" cellpadding="5" border="2"><tr><th align="center" bgcolor="yellow">Wayne Rooney</th><td align="center">1<input type="radio" name="Wayne Rooney" value="1"/></td><td align="center">2<input type="radio" name="Wayne Rooney" value="2"/></td><td align="center">3<input type="radio" name="Wayne Rooney" value="3"/></td><td align="center">4<input type="radio" name="Wayne Rooney" value="4"/></td></tr><th align="center" bgcolor="yellow">John Smith</th><td align="center">1<input type="radio" name="John Smith" value="1"/></td><td align="center">2<input type="radio" name="John Smith" value="2"/></td><td align="center">3<input type="radio" name="John Smith" value="3"/></td><td align="center">4<input type="radio" name="John Smith" value="4"/></td></tr><th align="center" bgcolor="yellow">Eric Cantona</th><td align="center">1<input type="radio" name="Eric Cantona" value="1"/></td><td align="center">2<input type="radio" name="Eric Cantona" value="2"/></td><td align="center">3<input type="radio" name="Eric Cantona" value="3"/></td><td align="center">4<input type="radio" name="Eric Cantona" value="4"/></td></tr><th align="center" bgcolor="yellow">Cristiano Ronaldo</th><td align="center">1<input type="radio" name="Cristiano Ronaldo" value="1"/></td><td align="center">2<input type="radio" name="Cristiano Ronaldo" value="2"/></td><td align="center">3<input type="radio" name="Cristiano Ronaldo" value="3"/></td><td align="center">4<input type="radio" name="Cristiano Ronaldo" value="4"/></td></tr></table><p><br /><center/><input type="submit" name="submit" value="VOTE!" /></p><input type="hidden" name="submitted" value="TRUE" />

      i hope that i've made it clearer now and apologies for how long this is. i look forward to your reply.thnx again.

        I redid your form so the names will work and used a little formatiing so it is not all on one line.

        <html>
        	<body>
        	<form action="registervote.php" method="post">
        	<table align="center" cellspacing="50" cellpadding="5" border="2">
        		<tr>
        			<th align="center" bgcolor="yellow">Wayne Rooney</th>
        			<td align="center">1
        				<input type="radio" name="Wayne_Rooney" value="1"/></td>
        			<td align="center">2
        				<input type="radio" name="Wayne_Rooney" value="2"/></td>
        			<td align="center">3
        				<input type="radio" name="Wayne_Rooney" value="3"/></td>
        			<td align="center">4
        				<input type="radio" name="Wayne_Rooney" value="4"/></td>
        		</tr>
        			<th align="center" bgcolor="yellow">John Smith</th>
        			<td align="center">1
        				<input type="radio" name="John_Smith" value="1"/></td>		
        			<td align="center">2
        				<input type="radio" name="John_Smith" value="2"/></td>		
        			<td align="center">3
        				<input type="radio" name="John_Smith" value="3"/></td>
        			<td align="center">4
        				<input type="radio" name="John_Smith" value="4"/></td>
        		</tr>
        			<th align="center" bgcolor="yellow">Eric Cantona</th>
        			<td align="center">1
        				<input type="radio" name="Eric_Cantona" value="1"/></td>
        			<td align="center">2
        				<input type="radio" name="Eric_Cantona" value="2"/></td>
        			<td align="center">3
        				<input type="radio" name="Eric_Cantona" value="3"/></td>
        			<td align="center">4
        				<input type="radio" name="Eric_Cantona" value="4"/></td></tr>
        			<th align="center" bgcolor="yellow">Cristiano Ronaldo</th>
        			<td align="center">1
        				<input type="radio" name="Cristiano_Ronaldo" value="1"/></td>
        			<td align="center">2
        				<input type="radio" name="Cristiano_Ronaldo" value="2"/></td>
        			<td align="center">3
        				<input type="radio" name="Cristiano_Ronaldo" value="3"/></td>
        			<td align="center">4
        				<input type="radio" name="Cristiano_Ronaldo" value="4"/></td>
        		</tr>	
        	</table>
        		<p>
        		<br /><center/>
        			<input type="hidden" name="submitted" value="TRUE" />
        			<input type="submit" name="submit" value="VOTE!" />
        	</form> 	
        		</p>
        	</body>
        </hyml>

        Then here is a simple check and assignment of variables you can chage to suit your form or database requirements.

        <?php 
        if(isset($_POST['Wayne_Rooney'])){
          $wayne = $_POST['Wayne_Rooney'];
        }
        if(isset($_POST['John_Smith'])){
          $john = $_POST['John_Smith'];
        }
        if(isset($_POST['Eric_Cantona'])){
          $eric = $_POST['Eric_Cantona'];
        }
        if (isset($_POST['Cristiano_Ronaldo'])){
          $cristiano = $_POST['Cristiano_Ronaldo'];
        }
        echo "\$_POST['Wayne_Rooney'] = ".$wayne."<br />";
        echo "\$_POST['John_Smith'] = ".$john."<br />";
        echo "\$_POST['Eric_Cantona'] = ".$eric."<br />";
        echo "\$_POST['Cristiano_Ronaldo'] = ".$cristiano."<br />"
        ?> 
          Write a Reply...