Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-15-2008, 06:54 PM   PM User | #1
Danaldinho
New Coder

 
Join Date: Feb 2008
Posts: 95
Thanks: 14
Thanked 0 Times in 0 Posts
Danaldinho is an unknown quantity at this point
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?
Danaldinho is offline   Reply With Quote
Old 02-15-2008, 07:03 PM   PM User | #2
Andrew Johnson
Banned

 
Join Date: Feb 2008
Location: Winnipeg, Canada
Posts: 396
Thanks: 0
Thanked 29 Times in 29 Posts
Andrew Johnson can only hope to improve
I see

Quote:
".$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"]."
"; } } ?>
Andrew Johnson is offline   Reply With Quote
Old 02-15-2008, 07:09 PM   PM User | #3
outseeker
Regular Coder

 
Join Date: Feb 2008
Location: Australia baby!
Posts: 143
Thanks: 6
Thanked 3 Times in 3 Posts
outseeker has a little shameless behaviour in the past
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.
outseeker is offline   Reply With Quote
Old 02-15-2008, 10:40 PM   PM User | #4
Danaldinho
New Coder

 
Join Date: Feb 2008
Posts: 95
Thanks: 14
Thanked 0 Times in 0 Posts
Danaldinho is an unknown quantity at this point
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>
Danaldinho is offline   Reply With Quote
Old 02-15-2008, 10:51 PM   PM User | #5
Andrew Johnson
Banned

 
Join Date: Feb 2008
Location: Winnipeg, Canada
Posts: 396
Thanks: 0
Thanked 29 Times in 29 Posts
Andrew Johnson can only hope to improve
You need to name your PHP files with a .PHP extension, not a .HTML extension.
Andrew Johnson is offline   Reply With Quote
Old 02-16-2008, 03:54 AM   PM User | #6
outseeker
Regular Coder

 
Join Date: Feb 2008
Location: Australia baby!
Posts: 143
Thanks: 6
Thanked 3 Times in 3 Posts
outseeker has a little shameless behaviour in the past
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
__________________
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.

Last edited by outseeker; 02-16-2008 at 03:58 AM.. Reason: added mention of my previous suggestion
outseeker is offline   Reply With Quote
Old 02-16-2008, 12:35 PM   PM User | #7
Danaldinho
New Coder

 
Join Date: Feb 2008
Posts: 95
Thanks: 14
Thanked 0 Times in 0 Posts
Danaldinho is an unknown quantity at this point
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
Danaldinho is offline   Reply With Quote
Old 02-17-2008, 07:44 PM   PM User | #8
Danaldinho
New Coder

 
Join Date: Feb 2008
Posts: 95
Thanks: 14
Thanked 0 Times in 0 Posts
Danaldinho is an unknown quantity at this point
Anyone?
Danaldinho is offline   Reply With Quote
Old 02-17-2008, 07:50 PM   PM User | #9
outseeker
Regular Coder

 
Join Date: Feb 2008
Location: Australia baby!
Posts: 143
Thanks: 6
Thanked 3 Times in 3 Posts
outseeker has a little shameless behaviour in the past
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.
outseeker is offline   Reply With Quote
Old 02-17-2008, 07:59 PM   PM User | #10
Danaldinho
New Coder

 
Join Date: Feb 2008
Posts: 95
Thanks: 14
Thanked 0 Times in 0 Posts
Danaldinho is an unknown quantity at this point
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
Danaldinho is offline   Reply With Quote
Old 02-17-2008, 10:26 PM   PM User | #11
outseeker
Regular Coder

 
Join Date: Feb 2008
Location: Australia baby!
Posts: 143
Thanks: 6
Thanked 3 Times in 3 Posts
outseeker has a little shameless behaviour in the past
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.
outseeker is offline   Reply With Quote
Old 02-18-2008, 06:44 AM   PM User | #12
outseeker
Regular Coder

 
Join Date: Feb 2008
Location: Australia baby!
Posts: 143
Thanks: 6
Thanked 3 Times in 3 Posts
outseeker has a little shameless behaviour in the past
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.
outseeker is offline   Reply With Quote
Old 02-18-2008, 10:32 AM   PM User | #13
Danaldinho
New Coder

 
Join Date: Feb 2008
Posts: 95
Thanks: 14
Thanked 0 Times in 0 Posts
Danaldinho is an unknown quantity at this point
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?
Danaldinho is offline   Reply With Quote
Old 02-19-2008, 12:01 AM   PM User | #14
outseeker
Regular Coder

 
Join Date: Feb 2008
Location: Australia baby!
Posts: 143
Thanks: 6
Thanked 3 Times in 3 Posts
outseeker has a little shameless behaviour in the past
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.
outseeker is offline   Reply With Quote
Old 02-19-2008, 04:13 PM   PM User | #15
Danaldinho
New Coder

 
Join Date: Feb 2008
Posts: 95
Thanks: 14
Thanked 0 Times in 0 Posts
Danaldinho is an unknown quantity at this point
Here is a link: http://www.chamillionairechat.com/po...teDbTables.php

Danaldinho is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:52 AM.


Advertisement
Log in to turn off these ads.