Problem with bank call for listing

Asked

Viewed 76 times

-2

Good evening, I am developing a system of hours, but I was barred by a connection problem so I could do the listing of my database on the screen...

When I update the page it presents me two errors:

Warning: mysql_select_db() expects Parameter 2 to be Resource, Object Given in C: wamp64 www Harmonia - site Adm Admagenda.php on line 6

&

Warning: mysqli_query() expects Parameter 1 to be mysqli, string Given in C: wamp64 www Design Beauty and Harmony Beauty and Harmony - Adm Admagenda.php on line 11

I tried to tidy up according to the knowledge I have of php that in the case I’m still new, and I needed to solve this problem, in case what would be wrong?

my php code:

<?php
//require_once 'valida.php';
// definições de host, database, usuário e senha
include("../php/conexao.php");

mysql_select_db($bd, $link);

// cria a instrução SQL que vai selecionar os dados
$selecionar = "SELECT id, horas de segunda feira FROM horas_segunda";
// executa a query
$dados = mysqli_query($selecionar, $link) or die(mysql_error());
// transforma os dados em um array
$linha = mysql_fetch_assoc($dados);
// calcula quantos dados retornaram
$total = mysql_num_rows($dados);
?>

    <!DOCTYPE html>
    <html lang="pt-br" ng-app="AngularADM">

    <head>
        <meta charset="utf-8">
        <meta name="description" content="Beleza e Harmonia é um salão de beleza">
        <meta name="author" content="Miyomic">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Administração</title>
        <link rel="shortcut icon" href="../Imagens/favicon.png" type="image/x-png" />



        <link rel="stylesheet" type="text/css" href="../css/visual.css">

        <!-- responsivo -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
        <link href="../css/bootstrap.min.css" rel="stylesheet">
        <link href="../css/bootstrap.css" rel="stylesheet">
        <link href="../css/bootstrap-theme.css" rel="stylesheet">
        <link href="../css/bootstrap-theme.css.map" rel="stylesheet">
        <link href="../css/bootstrap-theme.min.css" rel="stylesheet">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
        <script src="../js/jqueryAtualizado.js"></script>
        <script src="../js/jqueryAtualizado.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
        <script src="../js/bootstrap.min.js"></script>
        <!-- Fim responsivo -->
        <script src="../js/angular.min.js"></script>
    </head>

    <body ng-controller="TempoHorasP1">

        <header id="header">
            <div class="container">
                <div class="row">
                    <div class="col-md-12">
                        <div class="block-left">
                            <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
                                <div class="container-fluid">
                                    <div class="navbar-header">
                                        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                                            <span class="sr-only">toggle navigation</span>
                                            <span class="icon-bar"></span>
                                            <span class="icon-bar"></span>
                                            <span class="icon-bar"></span>
                                            <span class="icon-bar"></span>
                                        </button>
                                        <div class="nav-logo col-md-8 righ-menu">
                                            <img src="../Imagens/logo-branco.png" alt="Studio 7 Hair">
                                        </div>
                                    </div>

                                    <div class="collapse navbar-collapse col-md-4" id="bs-example-navbar-collapse-1">
                                        <ul class="nav navbar-nav">
                                            <li class="active"><a href="AdmAgenda.php" class="item-menu-adm"><span>Seja bem vindo</span></a></li>
                                            <li><a class="item-menu-adm"><span>Configuração da Agenda</span><span class="sr-only">(current)</span></a></li>
                                            <li><a href="cadastro.html" class="item-menu-adm"><span>Cadastrar Administrador</span><span class="sr-only">(current)</span></a></li>
                                            <li><a href="Ajuda.php" class="item-menu-adm"><span>Solicitar Ajuda</span></a></li>

                                        </ul>
                                    </div>
                                </div>
                            </nav>
                        </div>
                    </div>
                </div>
            </div>
        </header>

        <section>
            <div class="container">
                <div class="row">
                    <h1 class="dourado texto-centro cabeca-adm">Beleza e Harmônia</h1>
                </div>

                <div class="alert alert-warning" role="alert">
                   <span class="glyphicon glyphicon-warning-sign"></span> <span class="texto-centro margin-canto10">As configurações selecionadas abaixo sera alterada no Agendamento online. Por favor tomar cuidado nas escolhas das opções seguinte, suas definições são online.
                        <br/> Em caso de congestionamento no servidor aguardar de 5 a 10 minutos.</span>

                </div>

            </div>

        </section>



        <div class="container">
            <div class="row">
                <h2 class="dourado texto-centro margin-top30 bold">Configuração da agenda online</h2>
            </div>

            <div class="row">

                <h3 class="texto-centro dourado">Agenda da 1º semana</h3>
                <hr />

                <div class="col-lg-12 center-block">
                    <div class="col-lg-2 texto-centro">
                        <p>Id</p>
                        <hr />
                    </div>

                    <div class="col-lg-2 texto-centro">
                        <p>Segunda</p>
                        <hr />
                    </div>






                    <?php

    if($total > 0) {

        do {

?>
                        <div class="row">
                            <div class="col-lg-2 texto-centro hora-banco">
                                <p>
                                    <?=$linha['id']?>
                                </p>

                            </div>

                            <div class="col-lg-2 texto-centro hora-banco">
                                <p>
                                    <?=$linha['horas_segunda']?>
                                </p>

                            </div>

                        </div>
                        <?php

        }while($linha = mysql_fetch_assoc($dados));

    }
?>


                </div>
            </div>


            <div class="form-alterar margin-top40 texto-centro">
                <h3 class="margin-top20">Área de alteração dos horários</h3>
            <form name="alterar" method="post" action="">

                <div class="row texto-centro">
            <span>Id = </span> <input type="text" class="campo-alterar texto-centro margin-canto10" placeholder="Insira o id da tabela" /> 

                    <span>Hora = </span> <input type="text" class="campo-alterar texto-centro margin-canto10" placeholder="Hora que deseja" />
            </div>

                            <div class="row texto-centro margin-top20">
                <button ng-click="atualizar()" value="descobrir" class="botao-atualizar">Atualizar <span class="glyphicon glyphicon-send branco"></span></button>

            </div>


            </form>


                <div class="alert alert-danger" role="alert">Para poder ter sucesso na alteração da agenda terá que ver qual id que deseja para poder selecionar</div>

                </div>

        </div>

    </body>


    </html>

    <?php
// tira o resultado da busca da memória
mysql_free_result($dados);
?>

my php connection:

<?php 

$host = "localhost";
$usuario = "root";
$senha = "";
$bd="admin_site";



$link = new mysqli($host, $usuario, $senha, $bd);


if($link -> connect_errno) {
    echo "Falha na conexão: (".$link->connect_errno.") ".$link->connect_error;
}


?>
  • Typo, reversed the parameters: mysqli_query($link, $selecionar) and this here is wrong: or die(mysql_error()); would be or die(mysqli_error($link));

2 answers

4


If I’m wrong you reversed, it’s the $link first. And on or die(mysql_error()) you used absoleta function mysql different from the one you’re using. The right one would be:

$dados = mysqli_query($link,$selecionar) or die(mysqli_error($link));

On this line the parameters are inverted too, and again the confusion with mysql:

mysql_select_db($bd, $link);

The right thing would be:

mysqli_select_db($link,$bd);

But it is not necessary to select the comic again, since on that line $link = new mysqli($host, $usuario, $senha, $bd); you have already selected it, unless you have intentionally altered it.

Check out the documentation :

http://php.net/manual/en/mysqli.query.php

http://php.net/manual/en/mysqli.select-db.php

  • ah got it, and now this showing error on line 6 that in the case would be that mysql_select_db($bd, $link);

  • Inverted too

  • Ahh... I bought the booklet from PHP & Mysql arrived 3 days ago kkkk... but thank you guys

-1

You are mixing the procedural mysqli with the object oriented mysqli. The following is the correct one:

$selecionar = "SELECT id, horas de segunda feira FROM horas_segunda";
$dados = $link->query($selecionar);
$linha = $dados->fetch_assoc();
$total = $dados->num_rows;

Note: in the line oriented version of mysqli_select_db() is no longer needed.

Browser other questions tagged

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