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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Call PHP file in JavaScript Function for Updating MYSQL Table?

    Hello;

    I want to integrate a Java script Slot Machine game into my script.

    You can see demo here ; http://odhyan.com/slot/

    And also git hub is here ; https://github.com/odhyan/slot you can see all JS files here.

    I created a Point Coloumn in User Table that people can play the game with this Point.

    I think this JS Function in slot.js checking if user won the game or lose.

    Code:
    function printResult() {
            var res;
            if(win[a.pos] === win[b.pos] && win[a.pos] === win[c.pos]) {
                res = "You Win!";
            } else {
                res = "You Lose";
            }
            $('#result').html(res);
        }
    Here is my DB;



    So i want to add +100 Point if user won the bet.

    I made this PHP codes Uptading points For userid "1".

    addpoint.php

    PHP Code:
    <?php

    mysql_connect 
    ("localhost","username","password") or die (mysql_error());
    mysql_select_db('slot_machine');
    $pointsql mysql_query("SELECT * FROM user WHERE userid = 1");
    while (
    $row mysql_fetch_array($pointsql))
    {
    $row['point'] +=100;
    $addpoint =  mysql_query("UPDATE user SET point = '{$row['point']}' WHERE userid = 1");
    }

    ?>

    So how can i call or excute this PHP Codes in JavaScript function if user Win?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Java <> Javascript. Moving to the JS forum.
    PHP wise you'll need to set it up with a valid userid. Use of sessions are warranted to prevent a user from inputting their userid into the input data for the script and getting it for nothing.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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