1

Scenario: I'm trying to incorporate it so that when you click this button, it adds 1 to a value in the database.

I've read so many articles about AJAX today but no solution.

P.S. The query works fine directly from the command line.

This is what I've written so far but I think I'm completely missing something.

game.php

<script>
function logCountAdd(){
        var request = $.ajax({
            type: "GET",
            url: "logCountAdd.php"
        });
        request.done(function(msg ) {
            alert('Success');
            return;
        });
        request.fail(function(jqXHR, textStatus) {
            alert("Request failed: " + textStatus);
        });
};
</script>
</head>
<body>
<button type="button" onclick="logCountAdd()">Gather Resources</button>

logCountAdd.php

<?php
$connection = mysqli_connect("localhost","root","","users");

if (mysqli_connect_errno())
{
    echo 'NOT_OK';
}

mysqli_query($connection, "UPDATE uc_users 
        SET logCount = logCount + 1
        WHERE user_name='Gregory'";)

mysqli_close($connection);

echo 'OK';
?>

Problem: After I click the button, the value in the database does not change.

The Error Code: GET logCountAdd.php 500 (Internal Server Error)jquery-1.11.2.min.js:4 m.ajaxTransport.sendjquery-1.11.2.min.js:4 m.extend.ajaxgame.php:7 logCountAddgame.php:22 onclick

First question asked on here, sorry guys!

4
  • How specifically does this not work? Commented Jan 2, 2015 at 18:30
  • Can you explain and show us the error of your code ? Commented Jan 2, 2015 at 18:32
  • Sorry about that, updated it with a clear explanation of the problem! Commented Jan 2, 2015 at 18:32
  • Does your console give you error ? Can you open up the chrome console tab and see if there is any error in there ? Commented Jan 2, 2015 at 18:33

1 Answer 1

3
mysqli_query($connection, "UPDATE uc_users 
        SET logCount = logCount + 1
        WHERE user_name='Gregory'";)
                                  ^ misplaced semicolon

move it to after the close parenthesis. You may want to turn on error reporting to make debugging easier

error_reporting(E_ALL);
ini_set('display_errors','On');
Sign up to request clarification or add additional context in comments.

4 Comments

Wow. Wow. HA! Thankyou. Jesus Christ.
Honestly, such a rookie mistake. I've been tinkering with this file for hours, confused why it wouldn't work and completely overlooked that semicolon. Ugh.
@gregjw i suggest turning on errors (see php.net/error_reporting). you'll have an easier time debugging problems like this
Thank you! I'll do just that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.