Jump to content

Suggestions Please


corbeeresearch

Recommended Posts

Hi

 

I was playing with a poll, but for some reasons it won't email me(the bottom most part). Where did I go wrong?

 

Also any suggestions on how to improve this?

 

Thanks your the best guys!

 

<?php
include('config.php');
$name = strip_tags($_POST['name']);
$email = $_POST['email'];
$qst_id=strip_tags($_POST['qst_id']);
//if no ajax
$opt = strip_tags($_POST['opt']);
$s_id = $_SERVER['REMOTE_ADDR'];

//validate email 
if (!preg_match('/^.+@.+\..{2,3}$/',$email));
{
$email = 'email was blocked';
}
if (strlen($name) >= 50)
{
$name = 'name was blocked';
}


if ($opt == '')
{
$vote ="no";
}
elseif (($opt=='Yes') || ($opt=='No'))
{
$qt=mysql_query("insert into plus_poll_ans(s_id,qst_id,opt) values('".$s_id."','".$qst_id."','".$opt."')");
}
else
{
$vote = "no";
}

echo "<font size='2' face='Verdana' color='#000000' style='font-size:1.2em;'> Declaration of Faith</font>";

$qst_id=1; // change this to change the poll 

/* Find out the question first */
$fg=mysql_query("select qst from plus_poll where qst_id='".$qst_id."'");
$row=mysql_fetch_object($fg);

echo "<br><b><br>$row->qst</b><br>"; // display the question
/* for percentage calculation we will find out the total number
of answers ( options submitted ) given by the visitors */
$rt=mysql_num_rows(mysql_query("select ans_id from plus_poll_ans where qst_id='".$qst_id."'"));


/* Find out the answers and display the graph */
$query="select count(*) as no,qst,plus_poll_ans.opt from plus_poll,plus_poll_ans where plus_poll.qst_id=plus_poll_ans.qst_id and plus_poll.qst_id='".$qst_id."' group by opt desc ";
$rs=mysql_query($query);

//count the answers by yes or no
$count= "SELECT opt, count(opt) FROM plus_poll_ans GROUP BY opt desc"; 
$result = mysql_query($count) or die(mysql_error());

//separate the results
while($row = mysql_fetch_array($result)){
$total_opt[] = $row['count(opt)'];
}

// Print out result
echo "<table cellpadding='0' cellspacing='0' border='0' width='100%' >";

$i = 0;
while($noticia = mysql_fetch_array($rs)){
echo "<tr>
    <td width='5%' bgcolor='#F1F1F1'> <font size='1' face='Verdana' color='#000000'>$noticia[opt]</font></td>";
$width2=$noticia['no'] *10 ; /// change here the multiplicaiton factor //////////
$ct=($noticia[no]/$rt)*100;
$ct=sprintf ("%01.2f", $ct); // number formating 

echo "    <td width='20%' bgcolor='#F1F1F1'> <font size='1' face='Verdana' color='#000000'>($ct %)</font></td><td width='60%' align='left' bgcolor='#F1F1F1'> <img src='graph.jpg' height=10 width=$width2>";
echo "</td><td width='15%' align='right'>";
echo "<font size='1' face='Verdana' color='#000000'>".$total_opt[$i];
echo " votes";
echo "</font></td>";
echo  "</tr>";
echo "<tr>
    <td  bgcolor='#ffffff' colspan=2>"; 
echo "</td>";
echo "</tr>";
$i=$i+1;
}
echo "<tr><td></td><td></td><td><font size='1' face='Verdana' color='#000000'>Total Votes:</font></td><td align='right'>";
//count the total votes
$count = 'select count(ans_id) from plus_poll_ans';
$count = mysql_query($count);
$count = mysql_fetch_array($count);
$total_count = $count['count(ans_id)'];

echo "<font size='1' face='Verdana' color='#000000'>".$total_count." votes</font>";
echo "</td></tr>";
echo "</table>";
echo "</font>";


if ($vote!='no')
{
//email
$to = 'person1@example.com, person2@example.com';
$subject = 'Someone just made a declaration of faith';
$message = "Someone from the ip address ".$s_id;
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: Vote Detector <website@example.com>'. "\r\n";
if ($name!='')
{
	$message = $message." with the name ".$name;
}
if ($email!='')
{
	$message = $message." with email ".$email;
}
$message = $message." voted "."yes<br/>";
$message = $message."total number of people who declared their faith: ".$total_count." people<br/>";
$message = $message."with a total of ".$total_opt[0]." people saying yes";
$message = $message." and a total of ".$total_opt[1]." people saying no<br/>";
mail($to, $subject, $message, $headers);
}

?>


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.