php lastInsertId()。数组值形式中的未定义变量
我在传递php lastInsertId()。数组值形式中的未定义变量,php,arrays,forms,pdo,lastinsertid,Php,Arrays,Forms,Pdo,Lastinsertid,我在传递$last时遇到问题: $last = $db->lastInsertId(); 我需要从表单字段在数组中传递lastInsertId() <input type="text" name="remi[]" value= '<?php echo $last; ?>' /> 但从形式上看: remi: <input type="text" name="remi[]" value= '<?php echo $last; ?>' />&
$last
时遇到问题:
$last = $db->lastInsertId();
我需要从表单字段在数组中传递lastInsertId()
<input type="text" name="remi[]" value= '<?php echo $last; ?>' />
但从形式上看:
remi: <input type="text" name="remi[]" value= '<?php echo $last; ?>' /><br />
那么,如何在输入表单中传递$last
,以获取最后一个insert id
取而代之的是:
[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>
include_once'config/database.php';
$database=新数据库();
$db=$database->getConnection();
包括“objects/remisiones.php”;
$remision=新的REMISIONE($db);
包括“objects/detallemisiones.php”;
$detallemision=新的detallemision($db);
如果(美元邮政){
$remision->clienteId=$\u POST['clienteId'];
$remision->fecha=$\u POST['fecha'];
$remision->create();
$last=$db->lastInsertId();
$detallerimion->remi=$\u POST['remi'];
$detaleremision->trat=$\u POST['trat'];
$detallerimion->precio=$\u POST['precio'];
$detaleremision->cantidad=$_POST['cantidad'];
$detallerimion->create2();
}
?>
德国福查
客户
您还必须在html中使用isset
remi: <input type="text" name="remi[]" value= '<?php if (isset($last)) echo $last; ?>'
remi:您还必须在html中使用isset
remi: <input type="text" name="remi[]" value= '<?php if (isset($last)) echo $last; ?>'
remi:调用“Last”变量时,该变量不退出或未执行
尽管在调用变量时可以检查变量是否已设置,但最佳做法是使用空值分配脚本顶部的变量。这更好,因为在调用变量之前不必检查所有变量:
将以下内容放在文件顶部:
$last = "";
调用“Last”变量时,该变量不退出或未执行
尽管在调用变量时可以检查变量是否已设置,但最佳做法是使用空值分配脚本顶部的变量。这更好,因为在调用变量之前不必检查所有变量:
将以下内容放在文件顶部:
$last = "";
[表名称:detalleremisions:private]=>detalleremi[id]=>[remi]=>Array([0]=>[1]=>[2]=>)[表名称:detalleremisions:private]=>detalleremi[id]=>[remi]=>Array([0]=>[1]=>[2]=>)无变化。我得到了[table_name:detalleremisions:private]=>detalleremi[id]=>[remi]=>Array([0]=>[1]=>[2]=>),但在字段中最后一个插入id是确定的,remi 353没有更改。我得到了[table_name:detalleremisions:private]=>detalleremi[id]=>[remi]=>Array([0]=>[1]=>[2]=>),但在字段中最后一个插入id是ok的,remi 353