C
C
CakeCPP2019-09-25 22:14:59
PHP
CakeCPP, 2019-09-25 22:14:59

The response from the server to the script is not sent, how to fix it?

I have a table with 3 elements: server, question, answer. I need to return the answer depending on the server and the question, LFDLtvF.png
Could you tell me what I'm doing wrong?

function hook.onShowDialog(dialogID, style, title, button1, button2, text)
    if title:find("Капча") then 
        captchaServer = sampGetCurrentServerName()
        captchaServer = captchaServer:match("Diamond Role Play | (.+)")
        if captchaServer ~= nil then
            if captchaServer:find("Emerald") then 
                captchaServer = "Emerald"
            elseif captchaServer:find("Amber") then captchaServer = "Amber" 
            elseif captchaServer:find("Trilliant") then captchaServer = "Trilliant" 
            elseif captchaServer:find("Sapphire") then captchaServer = "Sapphire" 
            elseif captchaServer:find("Crystal") then captchaServer = "Crystal" 
            elseif captchaServer:find("Ruby") then captchaServer = "Ruby" 
            end 
        end
        captchaQuestion = text:match("Вопрос:\n(.+)\n\nВарианты ответа:")
        captchaAnswer[1] = text:match("1. (.+)\n2.")
        captchaAnswer[2] = text:match("2. (.+)\n3.")
        captchaAnswer[3] = text:match("3. (.+)\n4.")
        captchaAnswer[4] = text:match("4. (.+)\n\n{FFFFFF}Введите")
        sampAddChatMessage("{00A885}анти-капча{ffffff}: делаем запрос к базе данных", -1) 
        local serverEncoded = urlencode(captchaServer)
        local questionEncoded = urlencode(captchaQuestion)
        httpRequest('http://localhost/index.php?cap_server_2='..serverEncoded..'&cap_question_2='..questionEncoded, nil, function(response, code, headers, status)
            if response then 
                sampAddChatMessage("{00A885}анти-капча{ffffff}: ищем капчу в базе данных...", -1)
                 local trueAnswer = decodeJson(response.text)["cap_answer_to_lua"]
                 sampAddChatMessage('true answer: '..trueAnswer, -1)
            else 
                sampAddChatMessage("{00A885}анти-капча{ffffff}: капча в базе данных не найдена", -1)
            end
        end)
        isCaptchaActive = true
    end
end

$cap_server_2 = $_GET["cap_server_2"];
$cap_question_2 = $_GET["cap_question_2"];
$cap_answer_to_lua;

$sql = "SELECT server, question, answer FROM drp_captch WHERE server = '$cap_server_2' AND question = '$cap_question_2'";
$result = $conn->query($sql);
echo $sql;

if ($cap_question_2 && $cap_server_2) {

    if ($result->num_rows > 0) 
    {
        $IsCaptchInTable = true;
        $row = mysqli_fetch_array($result);
        $cap_answer_to_lua = $row["answer"];
        echo json_encode( $cap_answer_to_lua );
        $result->free();
    }
    else { 
        $IsCaptchInTable = false;
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SergeyRogulin, 2019-09-27
@CakeCPP

Instructions on the PHP side of the view:

$result = $conn->query($sql);
echo $sql; // Именно эта, но не строкой выше!

... will first print the SQL query, and then, if successful, the data itself will be output in JSON format. This very SQL query breaks your parsing in the LUA script:
local trueAnswer = decodeJson(response.text)["cap_answer_to_lua"]

D
dollar, 2019-09-26
@dollar

Could you suggest what I am doing wrong?

This is not how you debug your script. If you did the right thing, you would quickly find the mistake.
Learn to debug your programs, otherwise you have no right to be called a programmer. And when you come across a real paradox , then reduce it to 2-3 lines of code that anyone can easily reproduce on their own, and you can ask a question on the Toaster.
Besides, you didn't even ask that question. Because they did not describe the result. After all, the words "does not work" or "does not send" do not mean anything to a person who is ready to answer you. Where is the error text? You need to think at least a little about those to whom you are writing, to put yourself in their place. And I won’t even be able to start answering the current question, but I’m generally silent about the answer-solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question