hi guys
i have made a polling script
it is working fine with respect to displaying question and storing votes and displaying results
but i want it to use session concept for preventing multiple voting for users
can u guys give me guidance on that
i tried my hand at registering a session variable but it gives odd messages like this one below when i embed it in my page
==============================================Warning: Cannot send session cookie - headers already sent by (output started at c:\phpdev\www\last\index.php:11) in c:\phpdev\www\last\scripts\poll\poll.php on line 5
==============================================Warning: Cannot send session cache limiter - headers already sent (output started at c:\phpdev\www\last\index.php:11) in c:\phpdev\www\last\scripts\poll\poll.php on line 5
please help me on this guys
i am including the script below
just check it out and tell me
==============================================
<?php
include("config.php");
session_start();
if(!session_is_registered('voted')) {
$user_ip = $_SERVER['REMOTE_ADDR'];
$write_ip = "IP : $user_ip";
$fp = fopen("user_ip.txt", "a");
fputs($fp, $write_ip);
fclose($fp);
session_register('voted');
?>
<form name="poll" action="<?php print("$PHP_SELF"); ?>" method="get">
<?php
$question_query = "select * from question";
$question_query_result = mysql_query($question_query,$connectparam);
$question_query_row = mysql_fetch_row($question_query_result);
print("$question_query_row[1]<br><br>");
$answer_query = "select * from answer";
$answer_query_result = mysql_query($answer_query,$connectparam);
$i=1;
while($answer_query_row = mysql_fetch_row($answer_query_result)) {
print("$answer_query_row[2] <input type=\"radio\" name=\"user_vote\" value=\"$i\"><br>");
$i++;
}
?>
<br><input type="submit" name="Submit" value="Submit">
</form>
<?php
} else {
$user_vote = $_GET['user_vote'];
$store_vote_query = "UPDATE answer SET votes=votes+1 where id=$user_vote";
$store_vote_query_result = mysql_query($store_vote_query,$connectparam);
print("You have already voted.<br>Thank you.<br>The results are as follows.<br><br>");
$question_query = "select from question";
$question_query_result = mysql_query($question_query,$connectparam);
$question_query_row = mysql_fetch_row($question_query_result);
print("$question_query_row[1]<br><br>");
$answer_query = "select from answer";
$answer_query_result = mysql_query($answer_query,$connectparam);
$total_votes_query="select SUM(votes) from answer";
$total_votes = mysql_query($total_votes_query,$connectparam);
while($answer_query_row = mysql_fetch_row($answer_query_result)) {
$per = 0;
$per = $answer_query_row[3] / $total_votes;
$per = ROUND($per,2);
print("$answer_query_row[2] : $answer_query_row[3] ($per%) <br>");
}
}
?>
database scheme
structure of question table
CREATE TABLE question (
id tinyint(3) unsigned DEFAULT '0' NOT NULL,
question varchar(255) NOT NULL,
PRIMARY KEY (id),
UNIQUE id (id),
KEY id_2 (id)
);
structure of answer table
CREATE TABLE answer (
id tinyint(3) unsigned DEFAULT '0' NOT NULL,
question_id tinyint(3) unsigned DEFAULT '0' NOT NULL,
answer varchar(255) NOT NULL,
votes int(10) unsigned DEFAULT '0' NOT NULL,
PRIMARY KEY (id),
UNIQUE id (id),
KEY id_2 (id)
);
thanks anyway
i am sure many of you are gonna help me