Hello everyone, I hope you can help me, I have the following problem in my database, I need that when adding a row the next one is consecutive 1,2,3++, I already have the id
as primarykey
and autoincrement
but it takes the id of another table of a user who adds the line
In idTrip I need it to be 1 and so on
NOTE: If you can 0001 much better
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$razonSocial = $_POST["razonsocial"];
$idCliente = $_POST["idCliente"];
$cliente = $_POST["Cliente"];
$rfc = $_POST["rfc"];
$moneda = $_POST["moneda"];
$mercancia = $_POST["mercancia"];
$importe = $_POST["importe"];
$tipoOperacion = $_POST["TipoOperacion"];
$fechaAlta = $_POST["FechaAlta"];
$detalles = $_POST["detalles"];
$tipoTransporte = $_POST["TipoTransporte"];
$fechaSalida = $_POST["FechaSalida"];
$fechaLlegada = $_POST["FechaLlegada"];
$folio = $_POST["folio"];
$porigen = $_POST["porigen"];
$eorigen = $_POST["eorigen"];
$corigen = $_POST["corigen"];
$pdestino = $_POST["pdestino"];
$edestino = $_POST["edestino"];
$cdestino = $_POST["cdestino"];
$coberturas = $_POST["Coberturas"];
$poliza = $_POST["poliza"];
$cuota = $_POST["cuota"];
$prima = $_POST["prima"];
$gastosexp = $_POST["gastosexp"];
$iva = $_POST["iva"];
$total = $_POST["total"];
if($cliente == 'X'){
$cliente ='';
}else{
query("INSERT INTO merca (idViaje, idCliente, Cliente, rfc, moneda, mercancia, importe, TipoOperacion, FechaAlta, detalles, TipoTransporte, FechaSalida, FechaLlegada, folio, porigen, eorigen, corigen, pdestino, edestino, cdestino, Coberturas, poliza, cuota, prima, gastosexp, iva, total) VALUES ('".$idCliente."','".$idCliente."', '".$cliente."', '".$rfc."', '".$moneda."', '".$mercancia."', '".$importe."', '".$tipoOperacion."', '".$fechaAlta."', '".$detalles."', '".$tipoTransporte."', '".$fechaSalida."', '".$fechaLlegada."', '".$folio."','".$porigen."','".$eorigen."', '".$corigen."', '".$pdestino."', '".$edestino."', '".$cdestino."', '".$coberturas."', '".$poliza."', '".$cuota."', '".$prima."', '".$gastosexp."', '".$iva."', '".$total."')");
}
}
?>
<div class="row">
<div class="col-lg-12">
<div class="ibox float-e-margins">
<div class="ibox-content">
<form id="nclientes" name="nclientes" method="post" action="" class="form-horizontal">
<div class="form-group">
<h3 style="margin-left:20px;">Datos del Asegurado</h3>
<label class="col-sm-2 control-label">Razon Social</label>
<div class="col-sm-4">
<input name="razonsocial" type="text" autocomplete="off" required title="Completar campo" class="typeahead_2 form-control" <?php
if($_COOKIE["lvl"]==2){
echo 'value="'. $_COOKIE["usuario"] . '" disabled';
}
?> />
<input id="idCliente" name="idCliente" type="hidden" value="<?php
if($_COOKIE["lvl"]==2){
echo $_COOKIE["idUsuario"];
}
?>" />
In your query you have this:
Where in
VALUES
you have twice$idCliente
VALUES ('".$idCliente."','".$idCliente."',
doing the first to youidViaje
and the second toidCliente
(the second is fine).If in your database you already have idTrip, how should you
AUTO_INCREMENT
put as a value aidViaje
DEFAULT
Your query would look like this:
He 's taking you
idCliente
because that's what he's sending you:if your
idViaje
is autoincremental you don't need to send it.