I'm having this issue I have figure out a way to upload my data which is on .xls format and input the correct info on mysql. I'm using phpmyadmin and php to upload the file but right now I'm having trouble with primary keys... sorry I'm kinda new programming trough php, and I don't know why, once I define my primary key and the script send the data the primary key wont respect and don't assign the same id(primarykey) to the same value for example :
and my code to input data is as follows :
<?php
require_once 'db_con.php';
if(isset($_POST["submit_file"]))
{
$file = $_FILES["file"]["tmp_name"];
$file_open = fopen($file,"r");
while(($csv = fgetcsv($file_open, 1000, ",")) !== false)
{
$fecha= $csv[0];
$tipo = $csv[1];
$impresion = $csv[2];
$hojas= $csv[3];
$cadena_nombre = explode('(', $csv[4]);
$usuario =$cadena_nombre [0];
$usuario =$csv[4];
$stmt = $DBcon->prepare("INSERT INTO trabajo
(fecha,tipo,impresion,hojas,usuario)
VALUES(:fecha,:tipo,:impresion,:hojas,:usuario)");
$stmt->bindparam (':fecha', $fecha);
$stmt->bindparam(':tipo', $tipo);
$stmt->bindparam(':impresion', $impresion);
$stmt->bindparam(':hojas', $hojas);
$stmt->bindparam(':usuario', $usuario);
$stmt->execute();
}
}
echo "CSV Imported Successfully";
?>
My DDL looks like this :
CREATE TABLE `trabajo` (
`fecha` date NOT NULL,
`hojas` int(25) NOT NULL,
`impresion` int(25) NOT NULL,
`tipo` varchar(60) NOT NULL,
`usuario` varchar(60) NOT NULL,
`usuario_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE `trabajo`
ADD PRIMARY KEY (`usuario_id`);
--
-- AUTO_INCREMENT de las tablas volcadas
--
--
-- AUTO_INCREMENT de la tabla `trabajo`
--
ALTER TABLE `trabajo`
MODIFY `usuario_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=12592;
COMMIT;