Xtremer360 Posted March 16, 2010 Share Posted March 16, 2010 This is a voting script I downloaded and installed on my server and its not posting the result to the DB and I'm not quite sure why. My poll is located at kansasoutlawwrestling.com <?php foreach($_GET AS $key => $value) { ${$key} = $value; } foreach($_POST AS $key => $value) { ${$key} = $value; } include ("conf.php"); $db=mysql_connect($db_host,$database_user,$database_pass) or die("<b>MySQL Error:</b> Unable to connect to database please check that you have provided the correct <li>Database Login username<li>Database Login Password"); //Connect to database or give error if failed mysql_select_db($db_name,$db)or die("<b>MySQL Error:</b> Unable to select database please check that you have provided the correct <li>Database name"); if($action=="showpoll" && $id!=""){ $mpi=mysql_query("SELECT * FROM smp_cust"); $col=mysql_fetch_array($mpi); $pc=mysql_query("SELECT * FROM smp_quiz WHERE tm='$id'"); if(mysql_num_rows($pc)==1){ $now=mysql_fetch_array($pc); echo "<form onsubmit=\"javascript: return false;\"><table width=\"$col[pw]\" style='border:$col[boc] 1px solid;' cellpadding=0 cellspacing=0 bgcolor=\"$col[bbc]\"><TR bgcolor=\"$col[hlc]\" height=\"25\"><TD style='padding:4px;font-size:$col[hls]px;color:$col[ttc];' valign=middle><B>$now[title]</B></TD></TR><TR height=10><td><img src='images/space.gif' height=1 width=1></td></TR>"; $nx=mysql_query("SELECT * FROM smp_answer WHERE tm='$id'"); while($row=mysql_fetch_array($nx)){ echo "<TR height=\"25\"><td style='padding:2px;font:$col[bts]px verdana, tahoma; color:$col[btc]; text-align:left;' valign=top><input type=radio name=note value=\"$row[qid]\" onclick=\"begen($row[qid]);\"> $row[answer]</td></TR>"; } echo "<input type=hidden name=\"option\" id=\"option\" value=\"\">"; echo "<TR height=\"25\"><TD align=\"center\"><input type=\"submit\" onclick=\"javascript:fetch($id);\" style='color:$col[buc]' value=\"Submit\"><BR><BR><a href=\"/#showr\" onclick=\"javascript:result($id);\"><font size='1' color=\"$col[btc]\">See Results</a></font></TD></TR><TR height=10><td><img src='images/space.gif' height=1 width=1></td></TR></Table>"; echo "</form>"; } } if($action=="post_result" && $id!=""){ $ip=getenv(remote_addr); //$ip=rand(1,1000); $option=trim($option); $mpi=mysql_query("SELECT * FROM smp_cust"); $col=mysql_fetch_array($mpi); $pc=mysql_query("SELECT * FROM smp_quiz WHERE tm='$id'"); if(mysql_num_rows($pc)==1){ $now=mysql_fetch_array($pc); echo "<table width=\"$col[pw]\" style='border:$col[boc] 1px solid;' cellpadding=0 cellspacing=0 bgcolor=\"$col[bbc]\"><TR bgcolor=\"$col[hlc]\" height=\"25\"><TD style='padding:4px;font-size:$col[hls]px;color:$col[ttc];' valign=middle><B>$now[title]</B></TD></TR><TR height=10><td><img src='images/space.gif' height=1 width=1></td></TR>"; $prog=mysql_query("SELECT * FROM smp_result WHERE tm='$id' AND ip='$ip'"); if(mysql_num_rows($prog)>0){ echo "<TR height=\"25\"><td style='padding:2px;font:$col[bts]px verdana, tahoma; color:$col[btc]; text-align:left;' valign=top><b>You have already voted</b></td></TR>"; }else{ if($option!=""){ $ins=mysql_query("INSERT INTO smp_result SET point='$option',ip='$ip', tm='$id'"); }else{ echo "<TR height=\"25\"><td style='padding:2px;font:$col[bts]px verdana, tahoma; color:$col[btc]; text-align:left;' valign=top><b>Please select an option.</b></td></TR>"; } } $nx=mysql_query("SELECT * FROM smp_answer WHERE tm='$id'"); $total_results=mysql_query("SELECT * FROM smp_result WHERE tm='$id'"); $total_re=mysql_num_rows($total_results); while($row=mysql_fetch_array($nx)){ $opt=$row[qid]; $prong=mysql_query("SELECT * FROM smp_result WHERE tm='$id' AND point='$row[qid]'"); $tse=mysql_num_rows($prong); $result[$opt]=$tse; if($total_re>0){ $percentage=round(($tse/$total_re)*100,2); }else{ $percentage=0; } $wt=100-$percentage; if($percentage==0){ $tdw=1; }else{ $tdw=$percentage; } echo "<TR height=\"18\"><td style='padding:2px;font:$col[bts]px verdana, tahoma; color:$col[btc]; text-align:left;' valign=top>$row[answer]</td></TR>"; echo "<TR height=\"18\"><td style=\"padding-left:2px;\"><table width=\"80%\" align=left cellspacing=0 cellpadding=0><tr height=\"10\"><td bgcolor=\"$col[hlc]\" width=\"$tdw%\"><img src=\"images/spacer.gif\" width=\"0\" height=\"1\"></td><td width=\"$wt\" style=\"font:$col[bts]px verdana, tahoma; color:$col[btc]; text-align:left;\"><img src=\"images/spacer.gif\" width=\"1\" height=\"1\">$percentage%</td></tr></table></td></TR>"; echo "<tr height=\"10\"><td width=100%><img src=\"images/spacer.gif\" width=\"1\" height=\"1\"></td></tr>"; } echo "<tr height=\"5\"><td width=100%><img src=\"images/spacer.gif\" width=\"1\" height=\"1\"></td></tr>"; echo "<TR height=\"18\"><td style='padding:2px;font:$col[bts]px verdana, tahoma; color:$col[btc]; text-align:left;' valign=top>Total Votes: $total_re</td></TR>"; echo "<TR height=10><td><img src='images/space.gif' height=1 width=1></td></TR></Table>"; } } if($action=="see_result" && $id!=""){ $option=trim($option); $mpi=mysql_query("SELECT * FROM smp_cust"); $col=mysql_fetch_array($mpi); $pc=mysql_query("SELECT * FROM smp_quiz WHERE tm='$id'"); if(mysql_num_rows($pc)==1){ $now=mysql_fetch_array($pc); echo "<table width=\"$col[pw]\" style='border:$col[boc] 1px solid;' cellpadding=0 cellspacing=0 bgcolor=\"$col[bbc]\"><TR bgcolor=\"$col[hlc]\" height=\"25\"><TD style='padding:4px;font-size:$col[hls]px;color:$col[ttc];' valign=middle><B>$now[title]</B></TD></TR><TR height=10><td><img src='images/space.gif' height=1 width=1></td></TR>"; $nx=mysql_query("SELECT * FROM smp_answer WHERE tm='$id'"); $total_results=mysql_query("SELECT * FROM smp_result WHERE tm='$id'"); $total_re=mysql_num_rows($total_results); while($row=mysql_fetch_array($nx)){ $opt=$row[qid]; $prong=mysql_query("SELECT * FROM smp_result WHERE tm='$id' AND point='$row[qid]'"); $tse=mysql_num_rows($prong); $result[$opt]=$tse; if($total_re>0){ $percentage=round(($tse/$total_re)*100,2); }else{ $percentage=0; } if($percentage==0){ $tdw=1; }else{ $tdw=$percentage; } $wt=100-$percentage; echo "<TR height=\"18\"><td style='padding:2px;font:$col[bts]px verdana, tahoma; color:$col[btc]; text-align:left;' valign=top>$row[answer]</td></TR>"; echo "<TR height=\"18\"><td style=\"padding-left:2px;\"><table width=\"80%\" align=left cellspacing=0 cellpadding=0><tr height=\"10\"><td bgcolor=\"$col[hlc]\" width=\"$tdw%\"><img src=\"images/spacer.gif\" width=\"0\" height=\"1\"></td><td width=\"$wt\" style=\"font:$col[bts]px verdana, tahoma; color:$col[btc]; text-align:left;\"><img src=\"images/spacer.gif\" width=\"1\" height=\"1\">$percentage%</td></tr></table></td></TR>"; echo "<tr height=\"10\"><td width=100%><img src=\"images/spacer.gif\" width=\"1\" height=\"1\"></td></tr>"; } echo "<tr height=\"5\"><td width=100%><img src=\"images/spacer.gif\" width=\"1\" height=\"1\"></td></tr>"; echo "<TR height=\"18\"><td style='padding:2px;font:$col[bts]px verdana, tahoma; color:$col[btc]; text-align:left;' valign=top>Total Votes: $total_re</td></TR>"; echo "<TR height=10><td><img src='images/space.gif' height=1 width=1></td></TR></Table>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/195473-voting-poll/ Share on other sites More sharing options...
ksugihara Posted March 16, 2010 Share Posted March 16, 2010 That is the most confusing code I've ever read.... INDENT! it saves lives. Also, where is $ins being ran? Its the insert statement, but I dont see it ever being ran as a query... Link to comment https://forums.phpfreaks.com/topic/195473-voting-poll/#findComment-1027189 Share on other sites More sharing options...
Xtremer360 Posted March 16, 2010 Author Share Posted March 16, 2010 What should I do then? You would think that someone who puts out a script like that would have it working order. Link to comment https://forums.phpfreaks.com/topic/195473-voting-poll/#findComment-1027222 Share on other sites More sharing options...
ksugihara Posted March 16, 2010 Share Posted March 16, 2010 Do you actually know PHP? I guess more specifically, Im asking, are you looking for guidance as to getting this working, or are you looking for someone to make it work for you? Link to comment https://forums.phpfreaks.com/topic/195473-voting-poll/#findComment-1027223 Share on other sites More sharing options...
Xtremer360 Posted March 16, 2010 Author Share Posted March 16, 2010 Its just the fact that I don't know why someone would put a script out if doesn't work properly. I mean is it just doing: $result= mysql_query($ins) Link to comment https://forums.phpfreaks.com/topic/195473-voting-poll/#findComment-1027230 Share on other sites More sharing options...
ksugihara Posted March 16, 2010 Share Posted March 16, 2010 Yeah that does kinda suck... That might not be the issue, I was just asking if you did put that anywhere. You should really explore alternative scripts... this one does not appear to escape variables, or take any security precautions.... Link to comment https://forums.phpfreaks.com/topic/195473-voting-poll/#findComment-1027231 Share on other sites More sharing options...
Xtremer360 Posted March 16, 2010 Author Share Posted March 16, 2010 Thank you. I found this and it seems to be good does a lot. Too much but I think I like it. http://gallery.menalto.com/ Link to comment https://forums.phpfreaks.com/topic/195473-voting-poll/#findComment-1027261 Share on other sites More sharing options...
ksugihara Posted March 16, 2010 Share Posted March 16, 2010 thats a gallery... arent you just looking for a poll? Link to comment https://forums.phpfreaks.com/topic/195473-voting-poll/#findComment-1027266 Share on other sites More sharing options...
Xtremer360 Posted March 16, 2010 Author Share Posted March 16, 2010 oops gave you the wrong link but I did find one thank you Link to comment https://forums.phpfreaks.com/topic/195473-voting-poll/#findComment-1027286 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.