0

Hi.Im trying to create a program that would simply count of votes and save in database after voting of the students,results of all votes, and displaying people that have voted..
here's my html.

<h2><center>Select Candidates</h2>
<p><table cellspacing=5 cellpadding=5>
<tr>
<th>President:</th>
<tr></tr>
<td>1.Name presidents&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="pre1">&nbsp;&nbsp;<th><a href="">View Profile</th></a></td>
<tr></tr>
<td>2.Name presidents&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="pre2">&nbsp;&nbsp;<th><a href="">View Profile</th></a></td>
<tr></tr>
<td>3.Name presidents&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="pre3">&nbsp;&nbsp;<th><a href="">View Profile</th></a></td>
</tr>		
<tr>
<th>Vice President:</th>
<tr></tr>
<td>1.Name vice presidents&nbsp;&nbsp;&nbsp;<input type="radio" name="vice1">&nbsp;&nbsp;<th><a href="">View Profile</th></a></td>
<tr></tr>
<td>2.Name vice presidents&nbsp;&nbsp;&nbsp;<input type="radio" name="vice2">&nbsp;&nbsp;<th><a href="">View Profile</th></a></td>
<tr></tr>
<td>3.Name vice presidents&nbsp;&nbsp;&nbsp;<input type="radio" name="vice3">&nbsp;&nbsp;<th><a href="">View Profile</th></a></td>
</tr>
<tr>
<th>Secretary:</th>
<tr></tr>
<td>1.Name secretary&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="sec1">&nbsp;&nbsp;<th><a href="">View Profile</th></a></td>
<tr></tr>
<td>2.Name secretary&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="sec2">&nbsp;&nbsp;<th><a href="">View Profile</th></a></td>
<tr></tr>
<td>3.Name secretary&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="sec3">&nbsp;&nbsp;<th><a href="">View Profile</th></a></td>
</tr>
<tr>
<th>Treasurer:</th>
<tr></tr>
<td>1.Name treasurer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="tre1">&nbsp;&nbsp;<th><a href="">View Profile</th></a></td>
<tr></tr>
<td>2.Name treasurer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="tre2">&nbsp;&nbsp;<th><a href="">View Profile</th></a></td>
<tr></tr>
<td>3.Name treasurer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="tre3">&nbsp;&nbsp;<th><a href="">View Profile</th></a></td>
</tr>
<tr>
<th>P.R.O/Auditor:</th>
<tr></tr>
<td>1.Name P.R.O/Auditor&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="p1">&nbsp;&nbsp;<th><a href="">View Profile</th></a></td>
<tr></tr>
<td>2.Name P.R.O/Auditor&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="p2">&nbsp;&nbsp;<th><a href="">View Profile</th></a></td>
<tr></tr>
<td>3.Name P.R.O/Auditor&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="p3">&nbsp;&nbsp;<th><a href="">View Profile</th></a></td>
</tr>
</table></p>				 
<h2><center>
<input type="submit" value="     VOTE     "></h2>

tnx in advance if somebody would give working on php script...Godbless

Edited by takeshi: n/a

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by FlashCreations
0

ok but ill use a simple example for this one...
1st u need 2 files and a database

lets assume you got these tables, and ill make this simple but you can add more fields...

candidate
can_id = int, primary, autoincrement
name = varchar
votes = int
category = varchar

voter
voter_id = int, primary, autoincrement
name = varchar

then the files.

index.php

<?php
	
	if(isset($_GET['btnsubmit'])){
	
	$can = array($_GET['pres'],$_GET['vp']);
	

	
	mysql_connect('localhost','root',''); // i use default, but use your custom DBMS log-in
	mysql_select_db('takeshi'); // sample database, i user your name.. hehe
	
	foreach($can as $val){
	$sql = mysql_query( "UPDATE candidate SET votes=votes+1 where can_id='".$val."'" );
	}
	
	echo "<h1>vote complete!</h1>
	<a href='voteresult.php'>see all vote results</a>";
	
	
	}else{



	echo "<form method='get'>
      <h2><center>Select Candidates</h2>
	  
	  <h3>president:</h3>
	  1.) naruto <input type='radio' name='pres' value='1'><br />
	  2.) sasuke <input type='radio' name='pres' value='2'>
	  
	  <h3>vice-president:</h3>
	   1.) neji <input type='radio' name='vp' value='3'><br />
	  2.) lee <input type='radio' name='vp' value='4'>
	
		<p><input type='submit' name='btnsubmit' value='VOTE'></p>
	  </form>";
	  
	  }
	  
	  ?>

voteresult.php

<?php


mysql_connect('localhost','root',''); // i use default, but use your custom DBMS log-in
mysql_select_db('takeshi'); // sample database, i user your name.. hehe

echo "<h3>vote results</h3>";

$sql = mysql_query( "SELECT * FROM candidate WHERE category='president'" );
echo "<h4>President</hr>
<table>
<tr>
<th>name</th><th>votes</th>
</tr>";
while($row = mysql_fetch_array($sql)){
echo "<tr>
<td>".$row['name']."</td><td>".$row['votes']."</td>
</tr>";
}
echo "</table>";

$sql2 = mysql_query( "SELECT * FROM candidate WHERE category='vice-president'" );
echo "<h4>Vice-President</hr>
<table>
<tr>
<th>name</th><th>votes</th>
</tr>";
while($row2 = mysql_fetch_array($sql2)){
echo "<tr>
<td>".$row2['name']."</td><td>".$row2['votes']."</td>
</tr>";
}
echo "</table>";





?>

i just provide the major functionalities you seek and you should provide the rest... i recommend adding functionalities where the voter should have an account registered before they can vote.

0

ok but ill use a simple example for this one...
1st u need 2 files and a database

lets assume you got these tables, and ill make this simple but you can add more fields...

candidate
can_id = int, primary, autoincrement
name = varchar
votes = int
category = varchar

voter
voter_id = int, primary, autoincrement
name = varchar

then the files.

index.php

<?php
	
	if(isset($_GET['btnsubmit'])){
	
	$can = array($_GET['pres'],$_GET['vp']);
	

	
	mysql_connect('localhost','root',''); // i use default, but use your custom DBMS log-in
	mysql_select_db('takeshi'); // sample database, i user your name.. hehe
	
	foreach($can as $val){
	$sql = mysql_query( "UPDATE candidate SET votes=votes+1 where can_id='".$val."'" );
	}
	
	echo "<h1>vote complete!</h1>
	<a href='voteresult.php'>see all vote results</a>";
	
	
	}else{



	echo "<form method='get'>
      <h2><center>Select Candidates</h2>
	  
	  <h3>president:</h3>
	  1.) naruto <input type='radio' name='pres' value='1'><br />
	  2.) sasuke <input type='radio' name='pres' value='2'>
	  
	  <h3>vice-president:</h3>
	   1.) neji <input type='radio' name='vp' value='3'><br />
	  2.) lee <input type='radio' name='vp' value='4'>
	
		<p><input type='submit' name='btnsubmit' value='VOTE'></p>
	  </form>";
	  
	  }
	  
	  ?>

voteresult.php

<?php


mysql_connect('localhost','root',''); // i use default, but use your custom DBMS log-in
mysql_select_db('takeshi'); // sample database, i user your name.. hehe

echo "<h3>vote results</h3>";

$sql = mysql_query( "SELECT * FROM candidate WHERE category='president'" );
echo "<h4>President</hr>
<table>
<tr>
<th>name</th><th>votes</th>
</tr>";
while($row = mysql_fetch_array($sql)){
echo "<tr>
<td>".$row['name']."</td><td>".$row['votes']."</td>
</tr>";
}
echo "</table>";

$sql2 = mysql_query( "SELECT * FROM candidate WHERE category='vice-president'" );
echo "<h4>Vice-President</hr>
<table>
<tr>
<th>name</th><th>votes</th>
</tr>";
while($row2 = mysql_fetch_array($sql2)){
echo "<tr>
<td>".$row2['name']."</td><td>".$row2['votes']."</td>
</tr>";
}
echo "</table>";





?>

i just provide the major functionalities you seek and you should provide the rest... i recommend adding functionalities where the voter should have an account registered before they can vote.

ok..hmm i had already a database..and i already created a table for the voters/students..

students table:

CREATE TABLE `students` (
  `id` tinyint(4) NOT NULL auto_increment,
  `studno` int(10) NOT NULL,
  `name` varchar(32) NOT NULL,
  `course` varchar(8) NOT NULL,
  `year` int(32) NOT NULL,
  `department` varchar(25) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

candidates table:

CREATE TABLE `candidates` (
  `id` tinyint(4) NOT NULL auto_increment,
  `name` varchar(30) NOT NULL,
  `position` varchar(20) NOT NULL,
  `partyname` varchar(25) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

But in these tables and the tables that you've created were different.i dont have a field name vote in table candidates + can_id and categaory... But i do have name in students and studno which is the same with your voter_id..I know there's a revision in the above code..Hope to work all of these...

And how about in my static html code i posted first ..I used there "name of president", vicepresident,secretary,auditor,and treasurer..but it should be based on my database candidates..i already inserted a data in table candidate..Say for example,based on what i've posted html code :

<td>1.Name presidents&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="pre1">&nbsp;&nbsp;<th><a href="">View Profile</th></a></td>

it should look like this: but im not sure in my code aight.. :)

<td>1.<?php echo $name; ?>";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="pre1">&nbsp;&nbsp;<th><a href="">View Profile</th></a></td>

But not sure with this..

Edited by takeshi: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.