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.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Dec 2003
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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
    ---------

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    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.

  • #3
    New Coder
    Join Date
    Dec 2003
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey, thanks a lot for your advise/time Inigoesdr!
    I'll give it a go now!

  • #4
    New Coder
    Join Date
    Dec 2003
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    ---------

  • #5
    New Coder
    Join Date
    Dec 2003
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.ht...pt=ajax-poller
    Last edited by BK123; 03-06-2007 at 07:31 PM. Reason: wrong spelling

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    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".

  • #7
    New Coder
    Join Date
    Dec 2003
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #8
    New Coder
    Join Date
    Dec 2003
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #9
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    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).

  • #10
    New Coder
    Join Date
    Dec 2003
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #11
    New Coder
    Join Date
    Dec 2003
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #12
    New Coder
    Join Date
    Dec 2003
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

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