Results 1 to 5 of 5

Thread: Saving on the server and recalling data

  1. #1
    Join Date
    Sep 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Saving on the server and recalling data

    I'm about half way through this code, but I'm having trouble saving and recalling the data that I want saved. Right now I'm working on a function where the user clicks on either "Good" or "Bad" and the number next to each word displays the number of times that word has been clicked. I'm having trouble saving the number clicks that each word is getting so that when the page is reloaded, they aren't set back to zero. Here's what I have so far:

    Code:
    <script>
    function add_to_goodcount1(){
        var goodcount1=document.getElementById('goodcount1');
        var cstore = document.getElementById('good_counter_score1');
    
        cstore.value=parseInt(cstore.value)+1;
        goodcount1.innerHTML=cstore.value;
    }
    
    function add_to_badcount1(){
        var badcount1=document.getElementById('badcount1');
        var cstore = document.getElementById('bad_counter_score1');
    
        cstore.value=parseInt(cstore.value)+1;
        badcount1.innerHTML=cstore.value;
    }
    </script>
    
    <a href="javascript:add_to_goodcount1();">Good </a><input type="hidden" name="good_counter_score1" id="good_counter_score1" value='0'><span id="goodcount1">0</span>
    <p>&nbsp;</p>
    <a href="javascript:add_to_badcount1();">Bad </a><input type="hidden" name="bad_counter_score1" id="bad_counter_score1" value='0'><span id="badcount1">0</span>
    Any help on how to save this on the server would be very much appreciated. I'm really new to all this, so if you could possibly provide an example of how it should be written I'd appreciate it.

    Thanks!

  2. #2
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Use ajax. You'll need to create a new database and user, and then run the sql dump.

    goodbad.php
    PHP Code:
    <?php

    $count 
    $_POST['count'];

    mysql_connect("localhost""EDIT_DB_USER_HERE""EDIT_DB_PASS_HERE");
    mysql_select_db("EDIT_DB_NAME_HERE");

    mysql_query("UPDATE count SET count='$count'") or die(mysql_error());

    ?>
    Code:
    <script type="text/javascript">
    function ajaxFunction(count) {
    var xmlhttp;
    if (window.XMLHttpRequest) {
      xmlhttp=new XMLHttpRequest();
    } else if (window.ActiveXObject) {
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    xmlhttp.open("POST","goodbad.php",true);
    xmlhttp.send(POST);
    }
    
    function add_to_goodcount1(){
        var goodcount1=document.getElementById('goodcount1');
        var cstore = document.getElementById('good_counter_score1');
    
        cstore.value=parseInt(cstore.value)+1;
        goodcount1.innerHTML=cstore.value;
        ajaxFunction(cstore.value);
    }
    
    function add_to_badcount1(){
        var badcount1=document.getElementById('badcount1');
        var cstore = document.getElementById('bad_counter_score1');
    
        cstore.value=parseInt(cstore.value)+1;
        badcount1.innerHTML=cstore.value;
        ajaxFunction(cstore.value);
    }
    </script>
    
    <a href="javascript:add_to_goodcount1();">Good </a><input type="hidden" name="good_counter_score1" id="good_counter_score1" value='0'><span id="goodcount1">0</span>
    <p>&nbsp;</p>
    <a href="javascript:add_to_badcount1();">Bad </a><input type="hidden" name="bad_counter_score1" id="bad_counter_score1" value='0'><span id="badcount1">0</span>
    sql dump:
    Code:
    CREATE TABLE IF NOT EXISTS `count` (
      `count` int(11) NOT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    INSERT INTO `count` (`count`) VALUES(0);
    HTH
    - Josh

  3. #3
    Join Date
    Sep 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    how do I create the SQL dump?

  4. #4
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Do you have MySQL/PHP support?
    - Josh

  5. #5
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    && if so, do you have phpMyAdmin installed? [This is standard if you have cpanel as your host]
    - Josh

Bookmarks

Posting Permissions

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