Php Json Enconde Error

Asked

Viewed 31 times

0

I’m trying to solve a problem always PHP is returning the Else code "Wrong administrator password."

But the fact is that the password is correct... Well I 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.");

    }

?>
  • 1

    because Voce declared the function with @? @mysql_num_row

  • 2

    Have you tried taking @ out of front of functions to see if an error is occurring? Use of @ in PHP

  • Missed passing connection to function here => mysqli_query("$query");

  • @rray No mysql_ connection is optional. I just don’t understand why to use mysql_ and mysqli_ together.

1 answer

0

First, the@ sign in front of mysql_num_row means that execution errors will be deleted and therefore you will not be informed if they occur. I suggest you remove this symbol before anything else.

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";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.