Array with PHP and PostgreSQL

0

Hello, I have a problem with returning information from the database. It is returning me an unordered array and with information from another bank user.

Here is the Index:

<?php
  SESSION_START();
?>
<!DOCTYPE html>
<html lang = "pt-br">
  <head>
    <!-- MetaTags para aceitar caracteres especiais, ajustar compatibilidade com navegadores e dispositivos móveis -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Título -->
    <title>Test</title>

    <!-- Bootstrap CSS -->
    <link href="css/bootstrap.css" rel="stylesheet">
    <!-- Font-Awesome CSS -->
    <link href="css/font-awesome.min.css" rel="stylesheet">
  </head>
  <body>
    <?php echo '<pre>' . print_r($_SESSION, TRUE) . '</pre>';?>
    <!-- jQuery -->
    <script src="js/jquery.min.js"></script>
    <!-- Bootstrap JS -->
    <script src="js/bootstrap.min.js"></script>
    <script src="js/login.js"></script>
    <script>
  </body>
</html>

This is my PHP code:

include_once('connect.php');
    $msg_ok=false;
    $msg_error='Sistema fora do ar.';
    if(isset($_POST['telefone'], $_POST['nome'])):
        if($_POST['telefone']!=""):
            if($_POST['nome']!=""):
            $telefone=$_POST['telefone'];
            $nome=$_POST['nome'];
            $consulta=pg_query($connect, ("SELECT nome, cpf FROM mailing WHERE telefone='$telefone'"));
            if(pg_num_rows($consulta)>0):
                $msg_ok=true;
                $tel=pg_fetch_array($consulta);
                session_start();
                $msg_error="Logado corretamente.";
            else:
                $msg_error="Usuário ou nome incorretos.";
            endif;
        else:
            $msg_error="nome incorreta.";
        endif;
    else:
        $msg_error="Usuário não existe.";
    endif;
else:
    $msg_error="Todos os dados requiridos.";
endif;
$saidaJson=array('resposta' => $msg_ok, 'msg' => $msg_error);
echo json_encode($saidaJson);

I just want the user to enter the system by their mobile number (instead of a login and password), then PHP will return an array with the name, age, etc ...

I'm having a hard time making this comeback, but I'm researching, I do not have much experience with PHP and PostgreSQL, so I'm kind of lost.

    
asked by anonymous 18.08.2016 / 19:16

0 answers