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 03-06-2007, 06:38 PM   PM User | #1
BK123
New Coder

 
Join Date: Dec 2003
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
BK123 is an unknown quantity at this point
Poll/Vote Script not working!

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.ht...pt=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
---------
BK123 is offline   Reply With Quote
Old 03-06-2007, 06:45 PM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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
PHP Code:
$conn mysql_connect("localhost","username","password");
mysql_select_db("yourDbName",$conn); 
with
PHP Code:
//$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.
Inigoesdr is offline   Reply With Quote
Old 03-06-2007, 07:13 PM   PM User | #3
BK123
New Coder

 
Join Date: Dec 2003
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
BK123 is an unknown quantity at this point
Hey, thanks a lot for your advise/time Inigoesdr!
I'll give it a go now!
BK123 is offline   Reply With Quote
Old 03-06-2007, 07:26 PM   PM User | #4
BK123
New Coder

 
Join Date: Dec 2003
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
BK123 is an unknown quantity at this point
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 is offline   Reply With Quote
Old 03-06-2007, 07:30 PM   PM User | #5
BK123
New Coder

 
Join Date: Dec 2003
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
BK123 is an unknown quantity at this point
Don't know what this part of the instructions mean:
Quote:
Just put in connection and data and execute the file in your browser
Here's the page again: http://www.dhtmlgoodies.com/index.ht...pt=ajax-poller

Last edited by BK123; 03-06-2007 at 07:31 PM.. Reason: wrong spelling
BK123 is offline   Reply With Quote
Old 03-06-2007, 07:31 PM   PM User | #6
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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:
PHP Code:
$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".
Inigoesdr is offline   Reply With Quote
Old 03-06-2007, 07:35 PM   PM User | #7
BK123
New Coder

 
Join Date: Dec 2003
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
BK123 is an unknown quantity at this point
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 is offline   Reply With Quote
Old 03-06-2007, 07:38 PM   PM User | #8
BK123
New Coder

 
Join Date: Dec 2003
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
BK123 is an unknown quantity at this point
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.
BK123 is offline   Reply With Quote
Old 03-06-2007, 07:43 PM   PM User | #9
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Use [php ][/php] 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).
Inigoesdr is offline   Reply With Quote
Old 03-06-2007, 07:44 PM   PM User | #10
BK123
New Coder

 
Join Date: Dec 2003
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
BK123 is an unknown quantity at this point
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 is offline   Reply With Quote
Old 03-06-2007, 07:51 PM   PM User | #11
BK123
New Coder

 
Join Date: Dec 2003
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
BK123 is an unknown quantity at this point
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 is offline   Reply With Quote
Old 03-06-2007, 08:13 PM   PM User | #12
BK123
New Coder

 
Join Date: Dec 2003
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
BK123 is an unknown quantity at this point
Here's the ajax-poller.html code:
Sorry about the size!
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>

Last edited by BK123; 03-06-2007 at 08:15 PM.. Reason: wrong spelling
BK123 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 02:45 AM.


Advertisement
Log in to turn off these ads.