简体   繁体   中英

MySQL update query using AJAX and PHP

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.

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

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');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM