Hello everyone! I need your help. So I am currently working on my school project for web based voting system and I'm having a hard time to figure it out how to pass value 1 of multiple selected radio buttons to database. Here's my code so far:
Here is my voting form:
---CUT---
<form action="show-poll.php" method="post">
<?php
include('voting_connect.php');
{
$result = mysql_query("SELECT * FROM candidates WHERE c_position='President'")
or die(mysql_error());
echo "<center><table id='tables' class='sortable'>";
echo "<tr><th scope='col' abbr='' class='nobg'> </th> <th>President:</th></tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td scope='row' class='spec'>" . '<input name="vote1" type="radio" value="'.$row['c_ID'].'">' . "</td>";
echo "<td>";
echo '<a href=# alt=Candidate Profile rel=tooltip content="<div id=imagcon><img src='.$row['c_Location'].' class=tooltip-image/></div><div id=con>Running for:'.$row['c_position'].'</div><div id=con>Gender:'.$row['c_gender'].'</div><div id=con>Year:'.$row['c_Year'].'</div><div id=con>Course:'.$row['c_Course'].'</div><div id=con>Class:'.$row['c_Class'].'</div><div id=con>Partylist:'.$row['c_Partylist'].'</div>">'.$row['c_fname'].' '.$row['c_lname'].'</a>'.'<br>';
echo "</td>";
echo"</tr>";
}
echo"</table></center>";
}
?>
<br></br>
<?php
include('voting_connect.php');
{
$result = mysql_query("SELECT * FROM candidates WHERE c_position='Vice President'")
or die(mysql_error());
echo "<center><table id='tables' class='sortable'>";
echo "<tr><th scope='col' abbr='' class='nobg'> </th> <th>Vice President:</th></tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td scope='row' class='spec'>" . '<input name="vote2" type="radio" value="'.$row['c_ID'].'">' . "</td>";
echo "<td>";
echo '<a href=# alt=Candidate Profile rel=tooltip content="<div id=imagcon><img src='.$row['c_Location'].' class=tooltip-image/></div><div id=con>Running for:'.$row['c_position'].'</div><div id=con>Gender:'.$row['c_gender'].'</div><div id=con>Year:'.$row['c_Year'].'</div><div id=con>Course:'.$row['c_Course'].'</div><div id=con>Class:'.$row['c_Class'].'</div><div id=con>Partylist:'.$row['c_Partylist'].'</div>">'.$row['c_fname'].' '.$row['c_lname'].'</a>'.'<br>';
echo "</td>";
echo"</tr>";
}
echo"</table></center>";
}
?>
<br></br>
<?php
include('voting_connect.php');
{
$result = mysql_query("SELECT * FROM candidates WHERE c_position='Secretary'")
or die(mysql_error());
echo "<center><table id='tables' class='sortable'>";
echo "<tr><th scope='col' abbr='' class='nobg'> </th> <th>Secretary:</th></tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td scope='row' class='spec'>" . '<input name="vote3" type="radio" value="'.$row['c_ID'].'">' . "</td>";
echo "<td>";
echo '<a href=# alt=Candidate Profile rel=tooltip content="<div id=imagcon><img src='.$row['c_Location'].' class=tooltip-image/></div><div id=con>Running for:'.$row['c_position'].'</div><div id=con>Gender:'.$row['c_gender'].'</div><div id=con>Year:'.$row['c_Year'].'</div><div id=con>Course:'.$row['c_Course'].'</div><div id=con>Class:'.$row['c_Class'].'</div><div id=con>Partylist:'.$row['c_Partylist'].'</div>">'.$row['c_fname'].' '.$row['c_lname'].'</a>'.'<br>';
echo "</td>";
echo"</tr>";
}
echo"</table></center>";
}
?>
<br />
<br />
<input type="submit" value="Vote!"/>
---CUT---
this is the show-poll.php
---CUT---
<?php
if (isset($_POST['vote1']))
$vote=($_POST['vote1']);
// database connection
if (!$db_conn = mysql_connect('localhost', 'root', 'vertrigo'))
{
echo 'Could not connect to the database.<br>';
exit;
};
mysql_select_db('db_voting');
if (!empty($vote))
{
$vote = addslashes($vote);
$query = "update candidates set votecount = votecount + 1 where c_ID = '$vote'";
if(!($result = mysql_query($query, $db_conn)))
{
echo 'Could not connect to db<br>';
exit;
}
};
---CUT---