0

If i run the function, I get an internal server error.
Anyone know how to fix?
I want to make that if you press a button it changes from class, and also changes it in the database.

<?php
include_once("../../inc/database.php");

$id = $db->real_escape_string($_GET['id']);

$GetCurrent = $db->query("SELECT * FROM mailbox WHERE id=".$id);
$FetchCurrent = $GetCurrent->fetch_assoc();

if ($FetchCurrent['pinned'] == '0') [
$query1 = $db->query("UPDATE mailbox SET pinned='1' WHERE id=".$id);
} else {
$query2 = $db->query("UPDATE mailbox SET pinned='0' WHERE id=".$id);
}
?>    




        <script>
            function FlagMail(id){
                $.ajax({
                        type: "GET",
                        url: "pages/run/mail-flag.php",
                        data: {id: id},
                        cache: false,
                        success: function(result){
                            var element = document.getElementById(id);
                            element.classList.toggle("fa-flag-o");
                            element.classList.toggle("fa-flag");
                        },
                        error: function(jqXHR, textStatus, errorThrown){
                            alert(errorThrown);
                        }
                    });

            };
        </script>

I expect the output of the class changing, but I get the error.

  • Are you trying to fix the Ajax, or the php? Check the server error logs to find out what's wrong with the PHP, since "Internal Server Error" is such a broad "error". – aynber Dec 26 '18 at 19:09
  • 2
    `if ($FetchCurrent['pinned'] == '0') [` is incorrect syntax. `{` or `:` http://php.net/manual/en/control-structures.alternative-syntax.php You also can do that whole update with 1 query. – user3783243 Dec 26 '18 at 19:09
  • @user3783243 That worked, I'm feeling so bad right now. Thanks! – Lars Jansen Dec 26 '18 at 19:10
  • Good time to get a handle on error reporting. https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display and/or https://stackoverflow.com/questions/5127838/where-does-php-store-the-error-log-php5-apache-fastcgi-cpanel – user3783243 Dec 26 '18 at 19:12
  • Voting to close as a typographical error. – Funk Forty Niner Dec 26 '18 at 19:12
  • 1
    FYI sql injection vulnerabilities lie ahead – Rotimi Dec 26 '18 at 19:36

0 Answers0