PHP - Ayuda con error en código php

 
Vista:

Ayuda con error en código php

Publicado por sang soo (1 intervención) el 24/11/2014 02:00:06
Hola buenas noches, he hecho un código en html y php pero al correrlo con localhost me manda el siguiente error:

"Parse error: syntax error, unexpected '[' in C:\AppServ\www\VENTAS.php on line 48"

este es el código:

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
<html>
<body>
<?php
$host="localhost";
$user="JAVI";
$bd="test";
$con=mysql_connect($host,$user) or die("fallo conexión al servidor");
mysql_select_db($bd,$con) or die("fallo conexion a la BD");
?>
<?php
if(isset($_POST["B1"])){
$btn=$_POST["B1"];
}
if($btn=="Alta"){
$n_venta=$_POST["T1"];
$clav_p=$_POST["T2"];
$precio=$_POST["T3"];
$un=$_POST["T4"];
$fecha=$_POST["T5"];
$marca=$_POST["T6"];
$ID=$_POST["T7"];
$sql=("insert into ventas values('$n_venta','$clav_p','$precio','$un','$fecha','marca','$ID')");
$cs=mysql_query($sql,$con);
if($cs){
echo"<script language='javascript'>alert('La venta se dió de alta correctamente');
</script>";
}
else
{
echo"<script language='javascript'>alert('Alta de venta fallida');
</script>";
}
}
if(isset($_POST["B2"])){
$btn2=$_POST["B2"];
if($btn2=="Consulta"){
}
$n_venta=$_POST["T1"];
$clav_p=$_POST["T2"];
$precio=$_POST["T3"];
$un=$_POST["T4"];
$fecha=$_POST["T5"];
$marca=$_POST["T6"];
$ID=$_POST["T7"];
$sql=("select num_venta, clave, precio, unidades, fecha, marca from ventas where ID_empleado='$ID'");
$cs=mysql_query($sql,$con);
while ($res=mysql_fetch_array($cs)){
$n_venta=[0];
$clav_p=[1];
$precio=[2];
$un=[3];
$fecha=[4];
$marca=[5];
}
}
if(isset($_POST["B3"])){
$btn3=$_POST["B3"];
if($btn3=="Total"){
}
$n_venta=$_POST["T1"];
$precio=$_POST["T3"];
$un=$_POST["T4"];
$sql=("select precio * unidades from ventas where num_venta='$n_venta'");
$cs=mysql_query($sql,$con);
while ($res=mysql_fetch_array($cs)){
$n_venta=[0];
$precio=[1];
$un=[2];
}
}
?>
<form method="POST">
num venta:
<input type="text" name="T1"><br>
clave de producto:
<input type="text" name="T2"><br>
precio:
<input type="text" name="T3"><br>
unidades:
<input type="text" name="T4"><br>
fecha:
<input type="text" name="T5"><br>
marca:
<input type="text" name="T6"><br>
ID empleado:
<input type="text" name="T7"><br>
<input type="text" name="B1" value="Alta"><br>
<input type="text" name="B2" value="Consulta"><br>
<input type="text" name="B3" value="Total">
<input type="label" name="L1" value="<?php echo $cs ?>"><br><br>
</form>
</body>
</html>

ayuda por favor debo acabar un proyecto gracias salu2
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Ayuda con error en código php

Publicado por xve (6935 intervenciones) el 24/11/2014 09:29:14
Hola, he revisado la linea que te da el error, y la verdad es que no se que es esto:
1
$n_venta=[0];

Estas indicando que la variable $n_venta es el valor 0 de nada¿? tienes que indicar de que variable vas a coger el elemento 0.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Jorge Luis
Val: 27
Ha aumentado su posición en 69 puestos en PHP (en relación al último mes)
Gráfica de PHP

Ayuda con error en código php

Publicado por Jorge Luis (13 intervenciones) el 24/11/2014 18:02:31
Hola amigo, checalo poniendo las comillas dentro de:
$n_venta=["0"];
$precio=["1"];
$un=["2"];
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar