0
The following error message is appearing:
Notice: Undefined index: razao_social in C:\xampp2\htdocs\estudo\cadastroPrestador.php on line 5
Notice: Undefined index: nome_fantasia in C:\xampp2\htdocs\estudo\cadastroPrestador.php on line 6
Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp2\htdocs\estudo\cadastroPrestador.php on line 12
erro ao tentar cadastrar
connects.php:
<?php
$servidor='localhost';
$usuario='root';
$senha='';
$bancodedados='cis';
$strcon = mysqli_connect($servidor,$usuario,$senha,$bancodedados);
?>
cadastre.php:
<?php
include_once("conecta.php");
$idPrest = $_POST['id'];
$razaoSoc = $_POST['razao_social'];
$NomeFanta = $_POST['nome_fantasia'];
$NumCnpj = $_POST['CNPJ'];
$Tip = ['tipo'];
$sql = "INSERT INTO cadastroprestador(ID_PREST,Razão_Social,Nome_Fantasia,CNPJ) VALUES ('$idPrest', '$razaoSoc', '$NomeFanta', '$NumCnpj')";
mysqli_query($sql) or die ("erro ao tentar cadastrar");
mysql_close($strcon);
echo "Cadastrado Com sucesso";
?>
<html>
<head>
<title>Cadastro Prestador</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<!-- menu -->
<nav class="navbar navbar-inverse">
<div class="container-inverse">
<div class="navbar-header">
<a class="navbar-brand" href="#">Cadastro de Prestador</a>
</div>
</div>
</nav>
<div class="container">
<div class="panel panel-primary">
<div class="panel-heading">Prestador</div>
<div class="panel-body">
<form name "Ficha1" action="cadastroprestador.php" method="POST">
<div class="form-group" id="Prestador">
<div class="col-lg-2">
<label for="ex1">ID</label>
<input class="form-control" name="id" type="text" >
</div>
<div class="col-lg-12 form-group">
<label for="ex2">Razão Social</label>
<input class="form-control" name="razao_social" type="text">
</div>
<div class="col-lg-6 form-group">
<label for="ex3">Nome Fantasia</label>
<input class="form-control" name="nome_fantasia" type="text">
</div>
<div class="col-lg-6 form-group">
<label for="ex4">CNPJ</label>
<input class="form-control" name="CNPJ" type="text">
</div>
<div class="col-lg-6 form-group">
<label for="ex6">Tipo</label>
<select class="form-control" name="tipo">
<option>HOSPITAL</option>
<option>CLINICA</option>
<option>LABORATORIO</option>
<option>REMOÇÃO</option>
</select>
</div>
<div class="col-lg-6 form-group">
<label for="ex5">Indicação</label>
<select class="form-control" name="indicacao">
<option>Prospecção</option>
<option></option>
<option></option>
<option></option>
</select>
</div>
<button type="submit" class="btn btn-primary col-lg-2 right" id="btn_cad">Cadastro</button>
</form>
</div>
</div>
</div>
</body>
</html>
Solution: https://answall.com/questions/21714/como-resolver-um-notice-undefined-index
– Vinicius Gabriel
In the case of your code, the interesting thing would be to insert the isset as it explains in the topic I put the link. The "type" field assignment is without the $.post in the PHP file.
– Vinicius Gabriel
Whenever an answer solves your problem mark it as accepted. See how in https://i.stack.Imgur.com/jx7Ts.png and why in https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079
– user60252
Enjoy a tour https://answall.com/tour
– user60252