ayuda que no funciona "Agregar un evento JavaScript al botón "Enviar""
Publicado por Marcelino (11 intervenciones) el 08/05/2024 23:55:18
por favor para que alguien me ayude con este codigo. El problema es que no esta haciendo la operacion de enviar los datos a la bbdd.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
public function valida_registro(){
$fecha=$_POST['fecha'];
$cedula=$_POST['cedula'];
$busca=$_POST['buscar'];
if ($_POST['fecha'] && $_POST['cedula'])
{
$fecha = substr($_POST['fecha'],0,2).'-'.substr($_POST['fecha'],3,2).'-'.substr($_POST['fecha'],6,4);
$anio = substr($fecha,6,4);
$mes = substr($fecha,3,2);
$dia = substr($fecha,0,2);
$fechaM = $anio."-".$mes."-".$dia;
//$resultado1 = "SELECT * FROM deuda WHERE deuda.fecha = '$fechaM' AND deuda.cedula = '{$_POST['cedula']}'";
$resultado1 ="SELECT *
FROM vdeudaedificio
WHERE vdeudaedificio.fecha = '$fechaM'
AND vdeudaedificio.cedula = '{$_POST['cedula']}'";
//print_r($resultado1);
$resultado = @pg_query(Conectar::con(),$resultado1);
if (pg_num_rows($resultado)==0){
echo "<script type='text/javascript'>
alert('Este Registro no se encuentra en la Base de datos');
window.location='CancelaDeuda1.php';
</script>";
}
else
{
while ($seleccionado =@pg_fetch_array($resultado))
{
$nroapto = $seleccionado['nroapto'];
$cedula = $seleccionado['cedula'];
$monto = $seleccionado['monto'];
$nombre = $seleccionado['nombre'];
$fecha = $seleccionado['fecha'];
$anio = substr($fecha,0,4);
$mes = substr($fecha,5,2);
$día = substr($fecha,8,2);
// $monto = number_format($monto,2,',','.');
echo"<table border='1' bordercolor='#00CC99' bgcolor='#99CC00' align='center'>
<tr class='sr'>
</tr>";
echo " <tr>
<th>Apartamento
<td><input type='text' value='$nroapto' name='nroapto' readonly='true'></td></tr>
<tr>
<th>Edificio
<td><input type='text' value='$nombre' name='nombre' readonly='true'></td></tr>
<tr>
<th>Cédula
<td width='50'><input type='text' value='$cedula' name='cedula' readonly='true'></td></tr>
<th>Deuda
<td width='50'><input type='text' value='$monto' size='20' readonly='true' name='monto1' align='right'></td></tr>
<tr>
<th>Nro de Voucher
<td width='50'><input type='text' value='$voucher' required size='30' name='voucher' align='right'></td></tr>
</table><br>";
}
echo"<input type='submit' id='boton' name='action1' value='Enviar'/>";
?>
<script>
function enviarFormulario() {
// Recolectar datos del formulario
var fecha = document.getElementById("fecha").value;
var cedula = document.getElementById("cedula").value;
var monto = document.getElementById("monto").value;
var voucher = document.getElementById("voucher").value;
// Preparar datos para enviar
var datos = "fecha=" + fecha + "&cedula=" + cedula + "&monto=" + monto + "&voucher=" + voucher;
// Enviar petición a la base de datos (reemplazar con tu método AJAX)
var xhr = new XMLHttpRequest();
xhr.open("POST", "procesarPago.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onload = function() {
if (xhr.status === 200) {
// Procesar la respuesta del servidor (mostrar mensaje de éxito, actualizar la página, etc.)
alert("Pago procesado correctamente.");
} else {
alert("Error al procesar el pago. Inténtalo de nuevo.");
}
};
xhr.send(datos);
}
</script>
<?php
if (isset($_POST['action1']) and isset($_POST['fecha']) and isset($_POST['monto'])){
$fecha2 = substr($_POST['fecha'],6,4).'-'.substr($_POST['fecha'],3,2).'-'.substr($_POST['fecha'],0,2);
$totalmes = $_POST['monto']-$_POST['valor'];
$actualiza = "UPDATE deuda
set monto=$totalmes
WHERE deuda.cedula = '{$_POST['cedula']}'
AND deuda.fecha = '$fecha2'";
// $connect2 = pg_connect("host=localhost port=5432 dbname=administra user=postgres password=Wrap*/1808");
$cambiar = @pg_query(Conectar::con(),$actualiza);
}
$voucher = $_POST['voucher'];
$condominio = 'Condominio';
$valor = $_POST['valor'];
$hora =time();
if (isset($fecha2) and isset($condominio) and isset($valor) and isset($hora) and isset($voucher) and isset($_POST['monto'])) {
//$connect = pg_connect("host=localhost port=5432 dbname=administra user=postgres password=Wrap*/1808");
$cancelado = "INSERT INTO ingresos(voucher,fecha,descripcion,monto,hora)
VALUES ('$voucher','$fecha2',UPPER('$condominio'),$valor,$hora)";
$cancelar = @pg_query(Conectar::con(),$cancelado);
$dia = substr($_POST['fecha'],0,2);
$mes = substr($_POST['fecha'],3,2);
$anio = substr($_POST['fecha'],6,4);
$year = $dia.'-'.$mes.'-'.$anio;
if(@$cancelar)
{
?>
<script type='text/javascript'>
var agree=confirm("Canceló este Mes:'<?php echo $year?>'");
</script>
<?php
}
}
}
}
}
Valora esta pregunta
0