我有路過$last
一個問題:php lastInsertId()。在表單中值未定義變量數組
$last = $db->lastInsertId();
我需要在數組傳遞lastInsertId()
從表單字段,因爲
<input type="text" name="remi[]" value= '<?php echo $last; ?>' />
lastInsertId()
工程附近的形式,我得到正確的最後一個ID:
// here $last variable is ok
<?php if(isset($last)){ echo $last; }; ?>
但從形式:
remi: <input type="text" name="remi[]" value= '<?php echo $last; ?>' /><br />
我:
DetalleRemisiones Object
(
[conn:DetalleRemisiones:private] => PDO Object
(
)
[table_name:DetalleRemisiones:private] => detalleremi
[id] =>
[remi] => Array
(
[0] =>
Notice: Undefined variable: last in C:\xampp\htdocs\noe\remisiones_create_mas_remision3.php on line 85
[1] =>
Notice: Undefined variable: last in C:\xampp\htdocs\noe\remisiones_create_mas_remision3.php on line 93
[2] =>
Notice: Undefined variable: last in C:\xampp\htdocs\noe\remisiones_create_mas_remision3.php on line 98
)
那麼,怎樣才能在我輸入的形式得到最後插入ID傳遞$last
?
用於代替:
[remi] => Array
(
[0] => 256
[1] => 256
[2] => 256
)
這裏是我的代碼:
include_once 'config/database.php';
$database = new Database();
$db = $database->getConnection();
include_once 'objects/remisiones.php';
$remision = new remisiones($db);
include_once 'objects/detalleremisiones.php';
$detalleremision = new detalleremisiones($db);
if($_POST){
$remision->clienteId = $_POST['clienteId'];
$remision->fecha = $_POST['fecha'];
$remision->create();
$last = $db->lastInsertId();
$detalleremision->remi = $_POST['remi'];
$detalleremision->trat = $_POST['trat'];
$detalleremision->precio = $_POST['precio'];
$detalleremision->cantidad = $_POST['cantidad'];
$detalleremision->create2();
}
?>
<form action="remisiones_create_mas_remision3.php" method="post">
<tr>
<td>Fecha</td>
<td><input type='text' name='fecha' class='form-control' required></td>
</tr>
<tr>
<td>Cliente</td>
<td>
<?php
// read the clientes from the database
include_once 'objects/remisiones.php';
$remision = new Remisiones($db);
$stmt = $remision->readclientes();
echo "<select class='form-control' name='clienteId' required>";
echo "<option>Seleccione cliente...</option>";
while ($row_cliente = $stmt->fetch(PDO::FETCH_ASSOC)){
extract($row_cliente);
echo "<option value='{$id}'>{$clienteId} {$apellido} {$apellido2} {$nombre}</option>";
}
echo "</select>";
?>
</td>
</tr>
<br><br><br>
//
<?php // here $last variable is ok
if(isset($last)){ echo $last; }; ?>/
remi: <input type="text" name="remi[]" value= '<?php echo $last; ?>' /><br />
trat: <input type="text" name="trat[]" /><br />
precio: <input type="text" name="precio[]" /><br />
cantidad: <input type="text" name="cantidad[]" /><br />
remi: <input type="text" name="remi[]" value= '<?php echo $last; ?>' /><br />
trat: <input type="text" name="trat[]" /><br />
precio: <input type="text" name="precio[]" /><br />
cantidad: <input type="text" name="cantidad[]" /><br />
remi: <input type="text" name="remi[]" value= '<?php echo $last; ?>' /><br />
trat: <input type="text" name="trat[]" /><br />
precio: <input type="text" name="precio[]" /><br />
cantidad: <input type="text" name="cantidad[]" /><br />
<input type="submit" value="Enviar">
</form>
沒有,我嘗試過,但事實並非如此。 – rafpre
[表名:DetalleRemisiones:私人] => detalleremi [ID] => [雷米] =>數組 ( [0] => [1] => [2] => ) – rafpre