0
I made the creation of an html form accompanying a connection file and receiving data from this form (in php), however, when clicking on the input that calls the action receives, I get the following error:
Uncaught Error: Call to Undefined Function mysql_connect()
the codes are like this:
html:
<label>Nome</label><br />
<input type="text" name="nome" /><br />
<label>Idade</label><br />
<input type="number" name="idade" /><br />
<label>Telefone</label><br />
<input type="text" name="telefone" /><br />
<p>
<input type="submit" value="Cadastrar" />
</p>
php connection.
$con = mysql_connect("localhost", "root", ""); $db =
mysql_select_db("videoaula", $con);
if(!$con) { die("Não foi possível conectar ao banco de dados; " . mysql_error()); }
mysql_query("SET NAMES 'utf-8'"); mysql_query('SET character_set_connecton=utf-8'); mysql_query('SET character_set_client=utf-8'); mysql_query('SET character_set_results=utf-8');
php.:
require_once("connection/conexao.php");
$nome = $_POST["nome"];
$idade = $_POST["idade"];
$telefone = $_POST["telefone"];
$sql = "INSERT INTO `clientes` (`nome`, `idade`, `telefone`) VALUES ('$nome', '$idade', '$telefone')";
if(!$sql) {
echo("Houve um erro na inserção do banco de dados");
} else
{
echo("Dados inseridos com sucesso");
}
thanks since you
If you are using PHP 7, the functions
mysql_*
have been removed. Use functionsmysqli_*
in place.– Woss
possible duplicate https://answall.com/questions/173037/como-resolvero-erro-call-to-undefined-function-mysql-connect and here https://answall.com/questions/579/por-que-n%C3%A3o-should-use-fun%C3%A7%C3%B5es-do-tipo-mysql
– user60252
The mysql_connect() function has been discontinued.
– user60252