0
I’m running my first database (using a hospital as an example) through phpmyadmin, and the following error is being generated by attempting to register:
Fatal error: Uncaught Error: Call to Undefined Function redirecionarCadastro() in C: xampp htdocs projects project_hospital save-hospital.php:9 Stack trace: #0 C: xampp htdocs projects project_hospital index.php(66): include() #1 {main} thrown in C: xampp htdocs projeto_hospital projects save-hospital.php on line 9
The page that tells you the error is "save-hospital.php" below:
<?php
switch ($_REQUEST["acao"]) {
case 'cadastrar':
$sql = "INSERT INTO hospital (nome_hospital) VALUES ('".$_POST ["nome_hospital"]."')";
$res = $conn->query($sql) or die($conn->error);
redirecionarCadastro("consultar-hospital.php",$res);
if($res==true){
print "<div class='alert alert-success'>O cadastro foi realizado com sucesso! </div>";
}else{
print "<div class='alert alert-danger'>Não foi possível efetuar o cadastro! </div>";
}
break;
case 'editar':
$sql = "UPDATE hospital SET nome_hospital='".$_POST["nome_hospital"]."' WHERE id_hospital = ".$_POST["id_hospital"];
$res = $conn->query($sql) or die($conn->error);
redirecionarEditar("consultar-hospital",$res);
break;
case 'excluir':
$sql = "DELETE FROM hospital WHERE id_hospital = ".$_REQUEST["id_hospital"];
$res = $conn->query($sql) or die($conn->error);
redirecionarExcluir("consultar-hospial",$res);
break;
}
?>
A página "index.php" segue abaixo:
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="css/bootstrap.min.css">
<title>Hospital</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">Hospital</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="index.php">Início</span></a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Hospital
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="?page=cadastrar-hospital">Cadastrar</a>
<a class="dropdown-item" href="?page=consultar-hospital">Consultar</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Médico
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Cadastrar</a>
<a class="dropdown-item" href="#">Consultar</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Paciente
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Cadastrar</a>
<a class="dropdown-item" href="#">Consultar</a>
</div>
</li>
</ul>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<?php
include ("config.php");
switch (@$_REQUEST ["page"]) {
case 'cadastrar-hospital':
include ("cadastrar-hospital.php");
break;
case 'consultar-hospital':
include ("consultar-hospital.php");
break;
case 'salvar-hospital':
include ("salvar-hospital.php");
break;
default:
include ("main.php");
}
?>
</div>
</div>
</div>
<script src="js/jquery-3.5.1.slim.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
In the code snippet you posted there is no function definition
redirecionarCadastro
.– anonimo