I made a form in HTML and so far so good: I connected the php code with the database and filled it in, I don't get any errors in the code but I will see in my database table if the data has been inserted and nothing appears.
This is the php code:
<?php $conexion = mysqli_connect('localhost', 'root','','cliente') or die(mysqli_error($mysqli));
insertar($conexion); function insertar ($conexion){
$nombre = $_POST['nombre'];
$apellido = $_POST['apellido'];
$cedula = $_POST['cedula'];
$fecha = $_POST['fecha'];
$correo = $_POST['correo'];
$consulta = "INSERT INTO bdcliente(nombre, apellido, cedula, fecha, correo)
VALUES('$nombre','$apellido','$cedula','$fecha','$correo')" ;
mysqli_query($conexion, $consulta);
mysqli_close($conexion); } echo "Registrado" ?>
This is the html:
The database is named client and the table is named clientbd . This is the sql code:
-- phpMyAdmin SQL Dump
-- version 3.4.5
-- http://www.phpmyadmin.net
--
-- Servidor: localhost
-- Tiempo de generación: 14-09-2022 a las 05:21:41
-- Versión del servidor: 5.5.16
-- Versión de PHP: 5.3.8
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */;
--
-- Base de datos: `cliente`
--
-- --------------------------------------------------------
--
-- Estructura de tabla para la tabla `bdcliente`
--
CREATE TABLE IF NOT EXISTS `bdcliente` ( `Idcliente` int(11) NOT NULL DEFAULT '0', `Nombre` varchar(20) NOT NULL, `Apellido` varchar(20) NOT NULL, `Cedula` varchar(10) NOT NULL, `Fecha` date NOT NULL, `Correo` varchar(40) NOT NULL, PRIMARY KEY (`Idcliente`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Volcado de datos para la tabla `bdcliente`
--
INSERT INTO `bdcliente` (`Idcliente`, `Nombre`, `Apellido`, `Cedula`, `Fecha`, `Correo`) VALUES (0, '', '', '', '', '');
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Idcliente is PK but it is NOT autoincrementable, so in the INSERT you are not adding Idcliente. Either add the id to it or make it auto-incrementable:
Your problem is the field
Fecha
in the creation of the table you indicateBut when entering data the field is empty, in addition to what @Yussef indicates, so you should decide if you put the field manually or let MySQL put it through
DATE(NOW())
, the same thing happens from your PHP code, before entering the fieldFecha
You must verify the format of this field in your database and when posting it you must give it that format, generally in the base it is YYYY-MM-DD.