...

View Full Version : Poll/Vote Script not working!



BK123
03-06-2007, 07:38 PM
Hi everyone,
I suppose I'm not really surprised that this script isn't orking seen as I know nothing about databases/tables!...

Anyway, here's the script: http://www.dhtmlgoodies.com/index.html?whichScript=ajax-poller

I've created the database, I've edited the username/password and dbName as directed. I'm looking to obviously create tables in the database but there's a load of options and I don't know which to select.

I just want a poll with about 2 questions.

Also I'm not sure what this means: "Just put in connection and data and execute the file in your browser." Any idea? It's in the instructions.


Any help is really appreciated!

Thanks
BK123
---------

Inigoesdr
03-06-2007, 07:45 PM
You have to set the username, password, and dbname at the top of the createDBTables.php file, then open it in your browser so it can create the tables for you. They will be the same details you set in dbConnect.php. If you want you can replace
$conn = mysql_connect("localhost","username","password");
mysql_select_db("yourDbName",$conn);
with
//$conn = mysql_connect("localhost","username","password");
//mysql_select_db("yourDbName",$conn);
include('dbConnect.php'); in createDBTables.php to just use the information you already have in dbConnect.php. Make sure you delete the createDBTables.php file after your poll is working to prevent users from messing with your tables.

BK123
03-06-2007, 08:13 PM
Hey, thanks a lot for your advise/time Inigoesdr!
I'll give it a go now!:thumbsup:

BK123
03-06-2007, 08:26 PM
Hmmm, it's just coming up "No Database selected".

I've deleted the text above it which was just this:

/* This is the SQL that creates the default tables used in the poller script from www.dhtmlgoodies.com */

//SQL that creates the tables needed in this demo

I don't think this affects it.
The database name is correct.
Any ideas what else it could be or where to look?
I don't know databases/tables sadly...:(

BK123
---------

BK123
03-06-2007, 08:30 PM
Don't know what this part of the instructions mean:
Just put in connection and data and execute the file in your browser

Here's the page again: http://www.dhtmlgoodies.com/index.html?whichScript=ajax-poller

Inigoesdr
03-06-2007, 08:31 PM
No, those are just comments. You aren't selecting the database with mysql_select_db(); Make sure that line is right below the $conn = mysql_connect(); line and the database name is correct. You can add " or die(mysql_error())" temporarily right before the colon for both lines to tell you more information. ie:


$conn = mysql_connect("localhost","username","password") or die(mysql_error());
mysql_select_db("yourDbName",$conn) or die(mysql_error());

"Just put in connection and data and execute the file in your browser" means put YOUR database information there instead of the "username", "password", and "yourDbName".

BK123
03-06-2007, 08:35 PM
Now the "No database selected" is gone but the main page for the script is still showing:

".$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"]."

"; } } ?>


in the poll box.

BK123
03-06-2007, 08:38 PM
Yes the line is right below now, perhaps thats why it not showing "No Database selected" anymore.
The main page isn't working yet though.

Inigoesdr
03-06-2007, 08:43 PM
Use
tags(without the space) around your code so that it is formatted please. Check above that text in the file for a missing <?php tag you may have removed. If not post the whole file(if it's not huge).

BK123
03-06-2007, 08:44 PM
It's showing syntax error code on line 72, then on line 84.

Line 72 is ?> on ajax-poller.html coding:
}
?>
<a href="#" onclick="castMyVote(<? echo $pollerId; ?>,document.forms[0])"><img src="images/vote_button.gif"></a>

Line 84 is highlighted:
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

BK123
03-06-2007, 08:51 PM
Strangely, I persume, there seems to be some code missing from the file. See what I mean:

mysql_query("insert into poller_option(pollerID,optionText,pollerOrder)values('1','Good','3')");
mysql_query("insert into poller_option(pollerID,optionText,pollerOrder)values('1','Fair','3')");
mysql_query("insert into poller_option(pollerID,optionText,pollerOrder)values('1','Poor','4')");





That is the end of the CreateDbTables.php file. There's no ?>.
There should be, right? I've put one in and taken it off again but no difference.

BK123
03-06-2007, 09:13 PM
Here's the ajax-poller.html code:
Sorry about the size!:o
Line 72 is highlighted as is line 84.

<?

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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum