Saludos al intentar ingresar información en mi base de datos mediandte consultas preparadas en php PDO me genera los siguientes errores en primer lugar al intentar subir una imagen a una carpeta del servidor y su ruta a la bd y luego otro error al intentar pasar por bindvalue un objeto Datetime:
Warning: Undefined array key “imagen” in C:xampphtdocslacoroterapagar.php on line 37
Warning: Trying to access array offset on value of type null in C:xampphtdocslacoroterapagar.php on line 37
Fatal error: Uncaught Error: Object of class DateTime could not be converted to string in C:xampphtdocslacoroterapagar.php:106 Stack trace: #0 C:xampphtdocslacoroterapagar.php(106): PDOStatement->bindValue(‘:fecha_pago’, Object(DateTime), 2) #1 {main} thrown in C:xampphtdocslacoroterapagar.php on line 106
1 <?php
2 $nombre=!empty($_POST('nombre')) ? $_POST('nombre') : NULL;
3 $apellido=!empty($_POST('apellido')) ? $_POST('apellido') : NULL;
4 $letras=!empty($_POST('letras')) ? $_POST('letras') : NULL;
5 $documento=!empty($_POST('documento')) ? $_POST('documento') : NULL;
6 $banco=!empty($_POST('banco')) ? $_POST('banco') : NULL;
7 $numero_cuenta=!empty($_POST('numero_cuenta')) ? $_POST('numero_cuenta') : NULL;
8 $referencia=!empty($_POST('referencia')) ? $_POST('referencia') : NULL;
9 $monto=!empty($_POST('monto')) ? $_POST('monto') : NULL;
10 $imagen=!empty($_POST('imagen')) ? $_POST('imagen') : NULL;
11 $estatus=1;
12
13
14 session_start();
15 include "./php/conexion.php";
16
17 if(!isset($_SESSION('datos_logueo'))){
18 $url="login.php?error=Para poder pagar su plan debe iniciar sesión o registrarse";
19
20 }
21 $idp=$_GET('id_plan');
22 if( isset($_GET('id_plan'))){
23 $sql="select * from planes where id_plan=".$_GET('id_plan');
24 $resultado=$conexion->prepare($sql);
25 $resultado->execute();
26
27 while($fila=$resultado->fetch(PDO::FETCH_ASSOC)){
28
29 $duracion = $fila('duracion');
30
31
32
33 $fecha = new DateTime();
34 $fecha_venc = new DateTime();
35 $fecha_venc->modify( sprintf( '%+d months', intval( $duracion ) ) );
38 $carpeta="./imagenes/capturaspagos/";
37 $nombre_foto= $_FILES('imagen')('name');
38
39 //imagen.algo.jpg
40 $temp= explode( '.' ,$nombre_foto);
41 $extension= end($temp);
42
43 $nombrefinal = time().'.'.$extension;
44 if(!empty($_FILES('imagen')('name'))){
45 if(mime_content_type($_FILES('imagen')('tmp_name')) =='image/png' ||
46 mime_content_type($_FILES('imagen')('tmp_name'))=='image/jpeg'){
47 if(move_uploaded_file($_FILES('imagen')('tmp_name'), $carpeta.$nombrefinal)){
48 $sql1 = ("insert into pagos
49
50(nombre,apellido,tipo_doc,documento,banco,numero_cuenta,referencia,fecha_pago,fecha_vencimiento,monto,51 imagen,
52 id_usuario,id_plan,id_estatus) values
53 54(:nombre,:apellido,:tipo_doc,:documento,:banco,:numero_cuenta,:referencia,:fecha_pago,:fecha_vencimient55 o,:monto,:imagen,:id_usuario,:id_plan,:estatus)");
56 $stmt=$conexion->prepare($sql1);
57 $stmt->bindValue(":nombre", $nombre,PDO::PARAM_STR);
58 $stmt->bindValue(":apellido", $apellido,PDO::PARAM_STR);
59 $stmt->bindValue(":tipo_doc", $letras,PDO::PARAM_STR);
60
61 $stmt->bindValue(":documento", $documento,PDO::PARAM_STR);
62 $stmt->bindValue(":banco", $banco,PDO::PARAM_STR);
63 $stmt->bindValue(":numero_cuenta", $numero_cuenta,PDO::PARAM_INT);
64 $stmt->bindValue(":referencia",$referencia,PDO::PARAM_INT);
65 $stmt->bindValue(":fecha_pago",$fecha,PDO::PARAM_STR);
66 $stmt->bindValue(":fecha_vencimiento",$fecha_venc,PDO::PARAM_STR);
67 $stmt->bindValue(":monto",$monto,PDO::PARAM_STR);
68 $stmt->bindValue(":imagen",$nombrefinal,PDO::PARAM_STR);
69 $stmt->bindValue(":id_usuario",$id,PDO::PARAM_INT);
70 $stmt->bindValue(":id_plan",$idp,PDO::PARAM_INT);
71 $stmt->bindValue(":estatus",1,PDO::PARAM_INT);
72 $stmt->execute();
73 $url="../index.php?success";
74 //SI SE REALIZA LA SUBIDA REALIZO EL INSERT
75 }else{
76 $url="planes.php?error=No se pudo subir la imagen";
77
78 }
79
80 }else{
81
82 $url="planes.php?error=Por favor subir imagen jpg o png";
83
84 }
85
86 }
87
88 else{
89
90 $sql2 =("insert into pagos
91 92(nombre,apellido,tipo_doc,documento,banco,numero_cuenta,referencia,fecha_pago,fecha_vencimiento,monto,
93 id_usuario,id_plan,id_estatus) values
94 95(:nombre,:apellido,:letras,:documento,:banco,:numero_cuenta,:referencia,:fecha_pago,:fecha_vencimiento,96 :monto,:id_usuario,:id_plan,:estatus)");
97 $stmt2=$conexion->prepare($sql2);
98 $stmt2->bindValue(":nombre", $nombre,PDO::PARAM_STR);
99 $stmt2->bindValue(":apellido", $apellido,PDO::PARAM_STR);
100 $stmt2->bindValue(":tipo_doc", $letras,PDO::PARAM_STR);
101 $stmt2->bindValue(":documento", $documento,PDO::PARAM_STR);
102 $stmt2->bindValue(":banco", $banco,PDO::PARAM_STR);
103 $stmt2->bindValue(":numero_cuenta", $numero_cuenta,PDO::PARAM_INT);
104 $stmt2->bindValue(":referencia",$referencia,PDO::PARAM_INT);
105 $stmt2->bindValue(":fecha_pago",$fecha,PDO::PARAM_STR);
106 $stmt2->bindValue(":fecha_vencimiento",$fecha_venc,PDO::PARAM_STR);
107 $stmt2->bindValue(":monto",$monto,PDO::PARAM_STR);
108 $stmt2->bindValue(":id_isuario",$id,PDO::PARAM_INT);
109 $stmt2->bindValue(":id_plan",$idp,PDO::PARAM_INT);
110 $stmt2->bindValue(":estatus",1,PDO::PARAM_INT);
111 $stmt2->execute();
112 $url="../index.php?success";
113
114 }
115
116 }
117 }
118 ?>
HTML
<form action="pagar.php?id_plan=<?php echo $_GET('id_plan'); ?>" method="POST" enctype="multipart/form-data">
<div class="form-row">
<div class="form-group col-md-6">
<label for="nombre">Nombre(s) del titular de la cuenta</label>
<input type="text" class="form-control" maxlength="30" id="nombre" name="nombre" autocomplete="off" placeholder="nombre del titular de la cuenta o nombre de la empresa si es juridica">
</div>
<div class="form-group col-md-6">
<label for="apellido">Apellidos</label>
<input type="text" class="form-control" maxlength="30" id="apellido" name="apellido" autocomplete="off" placeholder="apellido del titular de la cuenta">
</div>
<div class="form-group col-md-6">
<label for="tipo_doc">Tipo de documento del titular de la cuenta</label>
<select name="tipo" class="form-control" onchange="cambia()">
<option data-lenght="8" value="1">C.I.
<option data-lenght="9" value="2">R.I.F
<option data-lenght="10" value="3">Pasaporte
</select>
</div>
<div class="form-group col-md-6">
<label for="tipo_doc">Prefijo del tipo de documento</label>
<select name="letras" id="letras" class="form-control">
<option value="V">V
<option value="E">E
</select>
</div>
<div class="form-group col-md-6">
<label for="documento">Documento</label>
<input type="text" class="form-control" maxlength="8" onkeyup="mascara(this,'.',patron1,true)" onkeypress="return ValidarNumeros(event)" autocomplete="off" name="documento" placeholder="escriba el número de cédula, rif ó pasaporte según sea el caso" id="documento" required>
</div>
<div class="form-group col-md-6">
<label for="banco">Banco desde donde se hizo la transferencia</label>
<select id="banco" class="form-control" name="banco" >
<option selected></option>
<option value="100% BANCO">100% BANCO
<option value="ABN AMRO BANK">ABN AMRO BANK
<option value="BANCAMIGA">BANCAMIGA
<option value="BANCO ACTIVO">BANCO ACTIVO
<option value="BANCO AGRICOLA">BANCO AGRICOLA
<option value="BANCO BANESCO">BANCO BANESCO
<option value="BANCO BICENTENARIO">BANCO BICENTENARIO
<option value="BANCO CARONI">BANCO CARONI
<option value="BANCO DE VENENEZUELA">BANCO DE VENENEZUELA
<option value="BANCO DEL CARIBE">BANCO DEL CARIBE
<option value="BANCO DEL TESORO">BANCO DEL TESORO
<option value="BANCO ESPIRITO SANTO">BANCO ESPIRITO SANTO
<option value="BANCO EXTERIOR">BANCO EXTERIOR
<option value="BANCO INTERNACIONAL DE DESARROLLO">BANCO INTERNACIONAL DE DESARROLLO
<option value="BANCO MERCANTIL">BANCO MERCANTIL
<option value="BANCO NACIONAL DE CREDITO">BANCO NACIONAL DE CREDITO
<option value="BANCO B.O.D">BANCO B.O.D
<option value="BANCO PLAZA">BANCO PLAZA
<option value="BANCO PROVINCIAL BBVA">BANCO PROVINCIAL BBVA
<option value="BANCO VENEZOLANO DE CREDITO">BANCO VENEZOLANO DE CREDITO
<option value="BANCRECER">BANCRECER
<option value="BANFANB">BANFANB
<option value="BANGENTE">BANGENTE
<option value="BANPLUS">BANPLUS
<option value="CITIBANK">CITIBANK
<option value="DELSUR">DELSUR
<option value="FONDO COMUN">FONDO COMUN
<option value="INSTITUTO MUNICIPAL DE CREDITO POPULAR">INSTITUTO MUNICIPAL DE CREDITO POPULAR
<option value="MIBANCA">MIBANCA
<option value="SOFITASA">SOFITASA
</select>
</div>
<div class="form-group col-md-6">
<label for="numero_cuenta">Número de cuenta del banco desde donde transfirió</label>
<input type="text" class="form-control" maxlength="20" onkeypress="return ValidarNumeros(event)" id="numero_cuenta" name="numero_cuenta" autocomplete="off" placeholder="Número de cuenta del banco desde donde transfirió">
</div>
<div class="form-group col-md-6">
<label for="referencia">Número de Referencia de la transferencia</label>
<input type="text" class="form-control" maxlength="20" onkeypress="return ValidarNumeros(event)" id="referencia" name="referencia" autocomplete="off" placeholder="Número de cuenta del banco desde donde transfirió">
</div>
<div class="form-group col-md-6">
<label for="monto">Monto de la transferencia</label>
<input type="text" class="form-control" id="monto" name="monto" placeholder="Monto en Bs.S de la transferencia realizada">
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="imagen">Captura de la transferencia (Opcional)</label>
<input type="file" name="imagen" id="imagen" class="form-control">
</div>
</div>
<div class="form-group col-md-6" style="margin:0px 470px;">
<button class="primary-btn order-submit">Pagar</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
</div>
</div>
</div>