How to resolve Call to Undefined Function mysql_connect() error

Asked

Viewed 100,270 times

6

I’m doing an IT inventory for registration 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 I solve this mistake?

Follow my code below.

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>
  • I’m using php 7

  • 1

    In PHP7 these functions no longer exist.

  • 2

    http://answall.com/questions/579/por-que-n%C3%A3o-should-use-fun%C3%A7%C3%B5es-do-tipo-mysql da uma lida se posso.

  • 1

    If you’re going to stun a code with Mysqli you can look that answer

  • @rray did an update and gave a different error and tried other ways and gave the same error .

  • As @rray said, this function has been discontinued (it is the 1st paragraph of the answer accepted in the original, indicated in the yellow frame).

Show 1 more comment

1 answer

18


The function mysql_connect() was discontinued.

Now it is used mysqli_connect().

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

This also applies to other commands starting with mysql_. Must be mysqli_.

Therefore:

mysqli_query($link, $query);
  • I made an update but this error appeared and I did it in other ways and nothing ;Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: The name requested

  • This happened because connection data is probably wrong.

Browser other questions tagged

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