How to solve the error Call to undefined function mysql_connect () [duplicate]

4

I'm doing an IT inventory to register and I want to connect to the database, but it's giving this error:

  

Fatal error: Uncaught Error: Call to undefined function   mysql_connect () in C: \ xampp \ htdocs \ xampp \ cadastrando.php: 9 Stack   trace: # 0 {main} thrown in C: \ xampp \ htdocs \ xampp \ cadastrando.php on   line 9

How could you resolve this error?

Below is my code.

HTML:

<form method="post" action="" onSubmit="">
        <fieldset>
            <legend>Sistema de Inventário</legend><br />

            <label class="borda">Setor: </label>
            <input class="form_inp" type="text" name="" size="30" required><br />

            <label class="borda">Usuário:</label>
            <input class="form_inp" type="text" id="" name="" size="30" required><br />

            <label class="borda">O/S :</label>
            <input class="form_inp" type="email" name="" size="30" required><br /><br />

            <label class="borda">Hd : </label>
            <input  class="form_inp"type="text"  name="" size="30" required><br />                      
            <hr />          
            <label class="borda">Memória:</label>
            <input class="form_inp" type="text" id="" name="" size="30" required><br />

            <label class="borda">Processador: </label>
            <input class="form_inp" type="text" id=""  name="" size="30" required><br /><br />
            <hr />
            <label class="borda">Cd/Dvd: </label>
            <select class="form_inp"  name="Dados"> 
                <option value="Sim">Sim</option> 
                <option value="Não">Não</option> 
            </select>

            <br />

            <label class="borda">Placa Mãe: </label>
            <input class="form_inp" type="text" id="" name="" size="30" required><br />

            <label class="borda">HostName: </label>
            <input class="form_inp"type="text" id="" name="" size="30" required><br /><br />

            <label class="borda">Monitor/Patrimônio/Marca/Modelo: </label>
            <input class="form_inp" type="text" id="" name="" size="30" required><br />

            <label class="borda">Nobreak/Patrimônio/Marca/: </label>
            <input class="form_inp" type="text" id="" name="" size="30" required><br />

            <label class="borda">Placa de Rede : </label>
            <input class="form_inp" type="text" id="" name="" size="30" required><br />

            <label class="borda">Placa de Vídeo: </label>
            <input class="form_inp" type="text" id="" name="" size="30" required><br />

            <hr />
            <input type="submit" style="float: right;" value="Cadastrar" >
            <input type="reset" style="float: right;" value="Limpar">

        </fieldset>

php / bancodedados:

  <html>
   <head><title>Cadastrando...</title></head>
    <body>
<?php
$host = "localhost";
$user ="roor";
$pass = "";
$banco = "cadastro";
$link = mysqli_connect("host", "user", "pass", "database"); 
mysqli_select_db($banco) or die (mysqli_error());
?>
<?php
$setor=$_POST['setor'];
$usuario=$_POST['usuario'];
$hd=$_POST['hd'];
$memoria=$_POST['memoria'];
$propressador=$_POST['processador'];
$cd=$_POST['cd'];
$placam=$_POST['placam'];
$host=$_POST['host'];
$monitor=$_POST['monitor'];
$nobreak=$_POST['nobreak'];
$placar=$_POST['placar'];
$placav=$_POST['placav'];
$sql=mysql_query("INSERT INTO setor(setor,usuario,hd,memoria,processador,cd,placam,host,monitor,nobreak,placar,plavav) VALUES('$setor,$usuario,$hd,$memoria,$processador,$cd,$placam,$host,$monitor,$nobreak,$placar,$placav'))");
?>
    </body>
</html>
    
asked by anonymous 22.12.2016 / 15:20

2 answers

12

The mysql_connect() function has been deprecated.

Now using mysqli_connect() .

$link = mysqli_connect("host", "user", "pass", "database");

This also applies to other commands that begin with mysql_ . They should be mysqli_ .

Therefore:

mysqli_query($link, $query);
    
22.12.2016 / 15:26
-1

In the last line you sneaked past the first parameter in the function mysql_query()

in case it would be

$sql = mysqli_query($link, "as passagens sql aqui");

Remembering that there are two ways to use mysqli

The way you did it structured

or using object orientation

    
22.12.2016 / 18:01