no se almacena los otros datos solo la imagen de la firma y su nombre pero los otros campos no
Publicado por Eduardo (185 intervenciones) el 09/02/2021 17:53:19
Hola a Todos.. espero esten muy bien.. Tengo la tabla1 con los campos id, nombre, nic, foto, firma la cual debe almacenar los datos ingresados en el formulario al ser enviados, pero solo me esta grabando la imagen png de la firma que se dibuja directamente en la pantalla (la almacena en una carpeta llamada signatures y el nombre del archivo en la tabla, pero no me graba los otros datos (nombre, nic.. el de la foto ya estoy trabajando en el pero por lo pronto quiero que almacene en la BD los valores aca dejo el code Que hago mal? por que si graba solo el nombre de la imagen y los campos otros no...? este ejemplo
ESTE ES LA TABLA:
ESTE ES EL CODIGO DEL SISTEMA...
ESTE ES LA TABLA:
1
2
3
4
5
6
7
CREATE TABLE `tabla1` (
`id` int(150) NOT NULL,
`nombre` varchar(150) NOT NULL,
`nic` varchar(50) NOT NULL,
`foto` varchar(50) NOT NULL,
`firma` varchar(50) NOT NULL
)
ESTE ES EL CODIGO DEL SISTEMA...
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<?php
error_reporting(0);
$dbName="basededatos";//nombre de la Base de datos
$username="usuario";//usuario
$password="contrasena";//contraseña
$tabla="tabla1";
$hostname="localhost";
mysql_connect($hostname,$username,$password) or print "Error en la Conexión";
mysql_select_db("$dbName") or print "Error en la Base de datos";
if(isset($_POST['signaturesubmit'])){
$signature = $_POST['signature'];
$nombrel = $_POST['nombre'];
$nicl = $_POST['nic'];
$fotol = $_POST['foto'];
$signatureFileName = uniqid().'.png';
$signature = str_replace('data:image/png;base64,', '', $signature);
$signature = str_replace(' ', '+', $signature);
$data = base64_decode($signature);
$file = 'signatures/'.$signatureFileName;
file_put_contents($file, $data);
$consulta="Insert into $tabla values('$id','$nombrel','$nicl','$foto','$signatureFileName')";
$resultado=mysql_query($consulta);
$msg = "<div class='alert alert-success'>Signature Uploaded</div>";
}
?>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<style>
#canvasDiv{
position: relative;
border: 2px dashed grey;
height:300px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<br>
<?php echo isset($msg)?$msg:''; ?>
<h2> </h2>
<hr>
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table width="105%" border="0" cellpadding="3" cellspacing="4" class="btn-lg">
<tr>
<td width="127" height="33">Nombre:</td>
<td width="628"><input type="text" name="nombre" id="nombre"></td>
</tr>
<tr>
<td height="34">NIC:</td>
<td><input type="number" name="nic" id="nic"></td>
</tr>
<tr>
<td height="36">Foto:</td>
<td><input type="file" name="foto" id="foto"></td>
</tr>
<tr>
<td height="27"> </td>
<td> </td>
</tr>
</table>
</form>
<br>
<br>
<div id="canvasDiv"></div>
<br>
<button type="button" class="btn btn-danger" id="reset-btn">Borrar</button>
<button type="button" class="btn btn-success" id="btn-save">Grabar</button>
</div>
<form id="signatureform" action="" style="display:none" method="post">
<input type="hidden" id="signature" name="signature">
<input type="hidden" name="signaturesubmit" value="1">
</form>
</div>
</div>
</body>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha256-pasqAKBDmFT4eHoN2ndd6lN370kFiGUFyTiUHWhU7k8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.5.0-beta4/html2canvas.min.js"></script>
<script>
$(document).ready(() => {
var canvasDiv = document.getElementById('canvasDiv');
var canvas = document.createElement('canvas');
canvas.setAttribute('id', 'canvas');
canvasDiv.appendChild(canvas);
$("#canvas").attr('height', $("#canvasDiv").outerHeight());
$("#canvas").attr('width', $("#canvasDiv").width());
if (typeof G_vmlCanvasManager != 'undefined') {
canvas = G_vmlCanvasManager.initElement(canvas);
}
context = canvas.getContext("2d");
$('#canvas').mousedown(function(e) {
var offset = $(this).offset()
var mouseX = e.pageX - this.offsetLeft;
var mouseY = e.pageY - this.offsetTop;
paint = true;
addClick(e.pageX - offset.left, e.pageY - offset.top);
redraw();
});
$('#canvas').mousemove(function(e) {
if (paint) {
var offset = $(this).offset()
//addClick(e.pageX - this.offsetLeft, e.pageY - this.offsetTop, true);
addClick(e.pageX - offset.left, e.pageY - offset.top, true);
console.log(e.pageX, offset.left, e.pageY, offset.top);
redraw();
}
});
$('#canvas').mouseup(function(e) {
paint = false;
});
$('#canvas').mouseleave(function(e) {
paint = false;
});
var clickX = new Array();
var clickY = new Array();
var clickDrag = new Array();
var paint;
function addClick(x, y, dragging) {
clickX.push(x);
clickY.push(y);
clickDrag.push(dragging);
}
$("#reset-btn").click(function() {
context.clearRect(0, 0, window.innerWidth, window.innerWidth);
clickX = [];
clickY = [];
clickDrag = [];
});
$(document).on('click', '#btn-save', function() {
var mycanvas = document.getElementById('canvas');
var img = mycanvas.toDataURL("image/png");
anchor = $("#signature");
anchor.val(img);
$("#signatureform").submit();
});
var drawing = false;
var mousePos = {
x: 0,
y: 0
};
var lastPos = mousePos;
canvas.addEventListener("touchstart", function(e) {
mousePos = getTouchPos(canvas, e);
var touch = e.touches[0];
var mouseEvent = new MouseEvent("mousedown", {
clientX: touch.clientX,
clientY: touch.clientY
});
canvas.dispatchEvent(mouseEvent);
}, false);
canvas.addEventListener("touchend", function(e) {
var mouseEvent = new MouseEvent("mouseup", {});
canvas.dispatchEvent(mouseEvent);
}, false);
canvas.addEventListener("touchmove", function(e) {
var touch = e.touches[0];
var offset = $('#canvas').offset();
var mouseEvent = new MouseEvent("mousemove", {
clientX: touch.clientX,
clientY: touch.clientY
});
canvas.dispatchEvent(mouseEvent);
}, false);
// Get the position of a touch relative to the canvas
function getTouchPos(canvasDiv, touchEvent) {
var rect = canvasDiv.getBoundingClientRect();
return {
x: touchEvent.touches[0].clientX - rect.left,
y: touchEvent.touches[0].clientY - rect.top
};
}
var elem = document.getElementById("canvas");
var defaultPrevent = function(e) {
e.preventDefault();
}
elem.addEventListener("touchstart", defaultPrevent);
elem.addEventListener("touchmove", defaultPrevent);
function redraw() {
//
lastPos = mousePos;
for (var i = 0; i < clickX.length; i++) {
context.beginPath();
if (clickDrag[i] && i) {
context.moveTo(clickX[i - 1], clickY[i - 1]);
} else {
context.moveTo(clickX[i] - 1, clickY[i]);
}
context.lineTo(clickX[i], clickY[i]);
context.closePath();
context.stroke();
}
}
})
</script>
</html>
Valora esta pregunta


0