
ERRO - Calculadora php (novato)
Publicado por jmsx (2 intervenciones) el 10/04/2014 18:44:01
Tengo el problema de que cuando pulso "=" se borra pero yo quiero no se calcula la operación, aquí dejo el código:
Mil gracias por adelantado :)
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
<head>
<title>Calculadora by Daniel Dominguez</title>
</head>
<body>
<form method="post">
<div>
<CENTER>
<input type="text" name="calculo" value="<?php if(isset($_GET['cadena'])){echo $_GET['cadena'];} ?>">
<table>
<tr>
<th><input type="submit" name="boton" value="7"/></th>
<th><input type="submit" name="boton" value="8"/></th>
<th><input type="submit" name="boton" value="9"/></th>
<th><input type="submit" name="boton" value="/"/></th>
</tr>
<tr>
<th><input type="submit" name="boton" value="4"/></th>
<th><input type="submit" name="boton" value="5"/></th>
<th><input type="submit" name="boton" value="6"/></th>
<th><input type="submit" name="boton" value="*"/></th>
</tr>
<tr>
<th><input type="submit" name="boton" value="1"/></th>
<th><input type="submit" name="boton" value="2"/></th>
<th><input type="submit" name="boton" value="3"/></th>
<th><input type="submit" name="boton" value="-"/></th>
</tr>
<tr>
<th><input type="submit" name="boton" value="0"/></th>
<th><input type="submit" name="boton" value=","/></th>
<th><input type="submit" name="boton" value="("/></th>
<th><input type="submit" name="boton" value=")"/></th>
</tr>
</table>
<input type="submit" name="boton" value="="/>
</CENTER>
</div>
</form>
</body>
</html>
<?php
if($_POST){
$cadena= $_POST['calculo'];
if($_POST['boton'] == "="){
$cadena = eval($cadena); //parte que falla
}else{
$cadena= ''.$cadena.''.$_POST['boton'].'';
}
header('Location: ?cadena='.$cadena);
}
?>
Mil gracias por adelantado :)
Valora esta pregunta


0