I am making a system to store data, very simply.
The problem: when saving it says that the connection variable does not exist, despite being included in the php file, then it says that I keep it correctly, but it does not save anything in the database
Conexion.php:
<?php
$host = "localhost";
$usua = "root";
$pass = "";
$base = "php_practica";
$cone = new mysqli($host, $usua, $pass, $base);
if ($cone->connect_error)
{
die("Error de Conexion: " . $cone->connect_error);
}
?>
Registration form:
<?php
include ("conexion.php");
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title> </title>
</head>
<body>
<form method="POST" action="procesar.php">
<h1 align="center">Bienvenido</h1>
<a href="index.html">
<ol>Pagina Principal</ol>
</a>
<a href="registrar.html">
<ol>Registrar</ol>
</a>
<a href="listado.html">
<ol>Listado</ol>
</a>
<a href="Sancion.html">
<ol>Sancion</ol>
</a>
<div> Ingrese su nombre </div>
<input type="text" name="nombre">
<div> Ingrese su apellido </div>
<input type="text" name="apellido">
<div> Ingrese su cedula </div>
<input type="text" name="cedula">
<div> Ingrese su rango </div>
<div>
<select name="rango">
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
</select>
</div>
<input type="submit" value="enviar">
</body>
</html>
Process.php
<?php
include ("conexion.php");
include ("funciones.php");
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title> </title>
</head>
<body>
<form method="POST" action="funciones.php">
<?php
bd_agregar($_REQUEST);
?>
</body>
</html>
Functions.php:
<?php
include ("conexion.php");
function bd_agregar($temp){
$nombre=$_REQUEST["nombre"];
$apellido=$_REQUEST["apellido"];
$cedula=$_REQUEST["cedula"];
$rango=$_REQUEST["rango"];
mysqli_query($cone,"INSERT INTO personal (nombre,apellido,cedula,rango)
VALUES ('$nombre','$apellido','$cedula','$rango')");
}
//Revisar si guardo correctamente//
if (mysqli_connect_errno($cone))
{
echo "Error al guardar los datos:" . mysqli_connect_error();
}
else
{
echo "Datos guardados correctamente:";
}
mysqli_close($cone);
?>
ERROR:
Notice: Undefined variable: cone in C: \ xampp \ htdocs \ PHP \ System of practice \ functions.php on line 9 --- Warning: mysqli_query () expects parameter 1 to be mysqli, null given in C: \ xampp \ htdocs \ PHP \ System of practice \ functions.php on line 10