Php Json Finds Error

0

I'm trying to solve a problem whenever PHP is returning the else's "wrong administrator password."

But the fact is that the password is correct ... Well I've tried everything so far.

<?php

    $email = $_POST['email'];
    $tempo = $_POST['tempo'];
    $plugin = $_POST['plugin'];

    $emaild = $_POST['emaild'];
    $password = $_POST['password'];

    $query55 = @mysql_num_rows(mysql_query("SELECT * FROM cadastro WHERE email='$emaild' AND senha='$password' "));

    if($query55 == 1) {

        $aleatorio = rand(6, 6); // 5 À 10 CARACTERES
        $valor = substr(str_shuffle("ABCDEFGHIJKLMNOPKRSTUVWXYZ0123456789"), 0, $aleatorio);

        date_default_timezone_set('America/Sao_Paulo');
        $buy_date = date("d/m/Y | H:i:s");

        $query = "SELECT * FROM plugin WHERE plugin_name='$plugin'"; 
        $result= @mysqli_query("$query"); // inicia a pesquisa
        while ($row = @mysql_fetch_array($result)) { 
        $plugin_name = stripslashes($row['plugin_name']); 
            if($tempo == 6){
                $plugin_custo = stripslashes($row['plugin_custo_1']);
            }elseif($tempo == 1){
                $plugin_custo = stripslashes($row['plugin_custo_2']);       
            }elseif($tempo == 'eterno'){
                $plugin_custo = stripslashes($row['plugin_custo_3']);                               
            }
        }

        if($tempo == 6){
            $tomorrow  = mktime (date("H"), date("i"), date("s"), date("m")+6, date("d"), date("Y"));   

        }elseif($tempo == 1){
            $tomorrow  = mktime (date("H"), date("i"), date("s"), date("m")+12, date("d"), date("Y"));  

        }elseif($tempo == 'permanente'){
            $tomorrow = "permanente";
        }   

        $db_host = "";
        $db_user = "";
        $db_pass = "";
        $db_name = "";


        $conn = new mysqli($db_host, $db_user, $db_pass, $db_name);
        // Check connection
        if ($conn->connect_error) {
            die("Connection failed: " . $conn->connect_error);
        } 

        $sql = "INSERT INTO compras (email, transaction_id, custo, buy_date, item_token, status, item_nome, tempo) VALUE ('$email',
            '$valor', '$plugin_custo', '$buy_date', '$valor', 'Pago', '$plugin', '$tempo') ";

        if ($conn->query($sql) === TRUE) {
            echo json_encode("Plugin adicionado com sucesso.");

            echo "<h1>TESTE</h1>";
        } else {
            echo "Error: " . $sql . "<br>" . $conn->error;
        }

        $sql2 = "INSERT INTO plugin_comprados (buy_date, plugin_token, plugin_owner, termino, plugin_name)
                VALUE ('$buy_date', '$valor', '$email', '$tomorrow', '$plugin')";

        if ($conn->query($sql2) === TRUE) {
                    echo json_encode("Plugin adicionado com sucesso.");

            echo "<h1>TESTE</h1>";
        } else {
            echo "Error: " . $sql . "<br>" . $conn->error;
        }


        return;

    }else {
        echo json_encode("Senha de administrador errada.");

    }

?>
    
asked by anonymous 31.01.2018 / 16:51

1 answer

0

First, the @ sign ahead of mysql_num_row means that execution errors will be suppressed and therefore you will not be informed about them if they occur. I suggest you remove this symbol first.

Secondly, the connection to the database is made later, which does not seem to make sense since one of the mandatory parameters of mysql_query is precisely the handler of the previously opened connection. See the example below:

$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);

$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";
    
31.01.2018 / 17:28