Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 3 123 LastLast
Results 1 to 15 of 31

Thread: Php Poll

  1. #1
    New Coder
    Join Date
    Feb 2008
    Posts
    95
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Php Poll

    I have this poll on my website now:

    http://www.chamillionairechat.com/poll/ajax-poller.html

    And I followed these instructions carefully from:

    http://www.dhtmlgoodies.com/index.ht...pt=ajax-poller

    But I don't know were I have gone wrong, because something isn't working right

    Does anyone know?

  • #2
    Banned
    Join Date
    Feb 2008
    Location
    Winnipeg, Canada
    Posts
    396
    Thanks
    0
    Thanked 29 Times in 29 Posts
    I see

    ".$inf["pollerTitle"].""; // Output poller title $resOptions = mysql_query("select * from poller_option where pollerID='$pollerId' order by pollerOrder") or die(mysql_error()); // Find poll options, i.e. radio buttons while($infOptions = mysql_fetch_array($resOptions)){ if($infOptions["defaultChecked"])$checked=" checked"; else $checked = ""; echo "

    ".$infOptions["optionText"]."
    "; } } ?>

  • #3
    Regular Coder
    Join Date
    Feb 2008
    Location
    Australia baby!
    Posts
    143
    Thanks
    6
    Thanked 3 Times in 3 Posts
    First thing that's noticable: You haven't used the full PHP open command. U have a "short open" command which probably won't work unless PHP is configured to accept it (which it isnt by default, and by the looks as it outputs it as text when you right click and "view source")

    For example, you can see this which should have been executed, not displayed.
    Code:
    <?
    
    require_once("dbConnect.php");
    
    ?>
    They wanna read <?PHP instead of <?. The close tags ?> are ok.

    If that in itself doesn't fix it, post again and we can check it out. The original code would be good, as when I hit View Source I can't see all of the code involved.
    outseeker - http://outer.reaches.dyndns.org/index.php
    I hope this helped someone. Due to this forums lame rep system penalising me for nothing, and admins inability to do anything about it, I'm sorry to say I will no longer be online here. Pride is important. Good Luck All.

  • #4
    New Coder
    Join Date
    Feb 2008
    Posts
    95
    Thanks
    14
    Thanked 0 Times in 0 Posts
    That didn't fix it

    And here is the full code:

    Code:
    <?PHP
    
    require_once("dbconnect.php");
    
    ?>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <HTML>
    <HEAD>
    	<?
    	@include($_SERVER['DOCUMENT_ROOT']."/config/metatags.inc");
    	?>	
    	<title>Ajax poller</title>
    	<style type="text/css">
    
    	
    	
    	/* DEMO CSS */
    	img{
    		border:0px;
    	}
    	
    	#mainContainer{
    		width:760px;
    		margin:0 auto;
    		text-align:left;
    		background-color:#FFF;
    		
    	}
    
    	#mainContent{
    		padding:10px;
    	}
    	
    	.clear{
    		clear:both;
    	}
    	</style>
    	<link rel="stylesheet" href="css/ajax-poller.css" type="text/css">
    	<script type="text/javascript" src="js/ajax.js"></script>
    	<script type="text/javascript" src="js/ajax-poller.js">	</script>
    
    </HEAD>
    <BODY>
    
    <form action="<? echo $_SERVER['PHP_SELF']; ?>" onsubmit="return false" method="post">
    <div id="mainContainer">
    	<div id="header"><img src="/images/heading3.gif"></div>
    	<div id="mainContent">
    	
    		<?
    		$pollerId = 3;	// Id of poller
    		?>
    		<!-- START OF POLLER -->
    		<div class="poller">
    		
    			<div class="poller_question" id="poller_question<? echo $pollerId; ?>">
    			<?			
    			
    			
    			// Retreving poll from database
    			$res = mysql_query("select * from poller where ID='$pollerId'");	
    			if($inf = mysql_fetch_array($res)){
    				echo "<p class=\"pollerTitle\">".$inf["pollerTitle"]."</p>";	// Output poller title
    				
    				$resOptions = mysql_query("select * from poller_option where pollerID='$pollerId' order by pollerOrder") or die(mysql_error());	// Find poll options, i.e. radio buttons
    				while($infOptions = mysql_fetch_array($resOptions)){
    					if($infOptions["defaultChecked"])$checked=" checked"; else $checked = "";
    					echo "<p class=\"pollerOption\"><input$checked type=\"radio\" value=\"".$infOptions["ID"]."\" name=\"vote[".$inf["ID"]."]\" id=\"pollerOption".$infOptions["ID"]."\"><label for=\"pollerOption".$infOptions["ID"]."\" id=\"optionLabel".$infOptions["ID"]."\">".$infOptions["optionText"]."</label></p>";	
    			
    				}
    			}			
    			?>			
    			<a href="#" onclick="castMyVote(<? echo $pollerId; ?>,document.forms[0])"><img src="images/vote_button.gif"></a>
    			</div>
    			<div class="poller_waitMessage" id="poller_waitMessage<? echo $pollerId; ?>">
    				Getting poll results. Please wait...
    			</div>
    			<div class="poller_results" id="poller_results<? echo $pollerId; ?>">
    			<!-- This div will be filled from Ajax, so leave it empty --></div>
    		</div>
    		<!-- END OF POLLER -->
    		<script type="text/javascript">
    		if(useCookiesToRememberCastedVotes){
    			var cookieValue = Poller_Get_Cookie('dhtmlgoodies_poller_<? echo $pollerId; ?>');
    			if(cookieValue && cookieValue.length>0)displayResultsWithoutVoting(<? echo $pollerId; ?>); // This is the code you can use to prevent someone from casting a vote. You should check on cookie or ip address
    		
    		}
    		</script>
    		
    		<p>This is an example of a poll script. It uses Ajax(Asyncron Javascript And XML) to send your vote to the server. Ajax is also used to return the results from this poll to your browser.</p>
    		<p>In this demo, I haven't limited the number of votes per user. This is something you can implement by setting the Javascript variable
    		useCookiesToRememberCastedVotes to true in the script or by implementing your own method.</p>
    	</div>
    	<div class="clear"></div>
    </div>
    </form>
    
    </BODY>
    </HTML>

  • #5
    Banned
    Join Date
    Feb 2008
    Location
    Winnipeg, Canada
    Posts
    396
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You need to name your PHP files with a .PHP extension, not a .HTML extension.

  • #6
    Regular Coder
    Join Date
    Feb 2008
    Location
    Australia baby!
    Posts
    143
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Got it sorted for ya mate. Good call about the extension Andrew. Unless you can edit the PHP.INI file for your server and add .html as a php executable extension you need to rename your ajax-poller.html to .php. Now it will just show the vote button and no poll. Because by default $pollerId=3. There is only one poll in the demo database so $pollerId=1;

    That worked fine for me! (once I remembered to execute createDbTables.php after editing it for dbname pass etc.) it's running at http://outer.reaches.dyndns.org/poller/ajax-poller.php till you say u got yours working.

    My previous suggestion of short open tags is irrelevant by the way. Their demo code worked ok without any changes there. Oh yeah, don't forget clickin here if ur a happy chappy! http://www.codingforums.com/reputation.php?p=656586
    Last edited by outseeker; 02-16-2008 at 03:58 AM. Reason: added mention of my previous suggestion
    outseeker - http://outer.reaches.dyndns.org/index.php
    I hope this helped someone. Due to this forums lame rep system penalising me for nothing, and admins inability to do anything about it, I'm sorry to say I will no longer be online here. Pride is important. Good Luck All.

  • #7
    New Coder
    Join Date
    Feb 2008
    Posts
    95
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Ok I fixed that now, thanks so much

    But outseeker how do you add the options for a user to vote?

    I can't see were to do it

    Thanks

  • #8
    New Coder
    Join Date
    Feb 2008
    Posts
    95
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Anyone?

  • #9
    Regular Coder
    Join Date
    Feb 2008
    Location
    Australia baby!
    Posts
    143
    Thanks
    6
    Thanked 3 Times in 3 Posts
    They are all in the MySQL Database you have set up mate. I recommend www.sql-front.com for easily connecting and manipulating these. Same details u put in the config file for username and password. Too easy
    outseeker - http://outer.reaches.dyndns.org/index.php
    I hope this helped someone. Due to this forums lame rep system penalising me for nothing, and admins inability to do anything about it, I'm sorry to say I will no longer be online here. Pride is important. Good Luck All.

  • #10
    New Coder
    Join Date
    Feb 2008
    Posts
    95
    Thanks
    14
    Thanked 0 Times in 0 Posts
    I don't understand though

    I have gone to poll and then admin and made a new poll

    But it wont show in the box on http://www.chamillionairechat.com/poll/ajax-poller.php

    I don't know what I am doing wrong and different to what you have done

  • #11
    Regular Coder
    Join Date
    Feb 2008
    Location
    Australia baby!
    Posts
    143
    Thanks
    6
    Thanked 3 Times in 3 Posts
    You mustn't have the correct details for username, password and database in your files. Edit them and ensure all details are correct. If they're correct, running the php file that installs tables will do it's job, and the admin will add polls.
    outseeker - http://outer.reaches.dyndns.org/index.php
    I hope this helped someone. Due to this forums lame rep system penalising me for nothing, and admins inability to do anything about it, I'm sorry to say I will no longer be online here. Pride is important. Good Luck All.

  • #12
    Regular Coder
    Join Date
    Feb 2008
    Location
    Australia baby!
    Posts
    143
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Did you get it to work for you mate?
    outseeker - http://outer.reaches.dyndns.org/index.php
    I hope this helped someone. Due to this forums lame rep system penalising me for nothing, and admins inability to do anything about it, I'm sorry to say I will no longer be online here. Pride is important. Good Luck All.

  • #13
    New Coder
    Join Date
    Feb 2008
    Posts
    95
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Nope

    The passwords are correct

    What do mean run the php file that installs the tables?

    Do you mean this: createDbTables.php

    If so, how do you run it?

    Do you mean just type it in your browser and click Go?

  • #14
    Regular Coder
    Join Date
    Feb 2008
    Location
    Australia baby!
    Posts
    143
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Yeah have you edited createDbTables.php? It wants your login and database details manually entered itself just like the admin file and the index file. If you run createdbtables.php with correct username etc it will add the database entries for the poller. Just put it's address in the address bar, the same way you are viewing your website. Like yourwebsite.com/poller/createdbtables.php. Then view the poller. It worked fine for me. Have you got a link for us dude? You seem to be havin a lot of trouble, but I have no link for me to play with and discover the fault ehehe it worked just fine on my system! You're not double clicking the createdbtables in your windows explorer or something are u? hehe it does need to be on the live server
    outseeker - http://outer.reaches.dyndns.org/index.php
    I hope this helped someone. Due to this forums lame rep system penalising me for nothing, and admins inability to do anything about it, I'm sorry to say I will no longer be online here. Pride is important. Good Luck All.

  • #15
    New Coder
    Join Date
    Feb 2008
    Posts
    95
    Thanks
    14
    Thanked 0 Times in 0 Posts


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •