
trato de pasar lo que esta en array en php y guardalo en mysql
Publicado por Reynaldo (7 intervenciones) el 19/04/2017 00:42:30
me sale este error
Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\prueba\compras\compras.php on line 28
Error:
compras.php
carritodecompras.php
Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\prueba\compras\compras.php on line 28
Error:
compras.php
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
<?php
session_start();
include '../conexion.php';
$arreglo=$_SESSION['carrito'];
$numeroventa=0;
$link = mysqli_connect("localhost", "root","","carrito de compras");
mysqli_select_db($link, "carrito de compras");
$tildes = $link->query("SET NAMES 'utf8'"); //Para que se muestren las tildes correctamente
$re = mysqli_query($link, "select * from compras order by numeroventa DESC limit 1") or die(mysqli_error());
while ($f=mysqli_fetch_array($re))
{
$numeroventa=$f['numeroventa'];
}
if($numeroventa==0){
$numeroventa=1;
}else{
$numeroventa=$numeroventa+1;
}
for($i=0; $i<count($arreglo);$i++){
mysqli_query($link,"insert into compras (numeroventa, imagen,nombre,precio,cantidad,subtotal) values(
".$numeroventa.",
'".$arreglo[$i]['Imagen']."',
'".$arreglo[$i]['Nombre']."',
'".$arreglo[$i]['Precio']."',
'".$arreglo[$i]['Cantidad']."',
'".($arreglo[$i]['Precio']*$arreglo[$i]['Cantidad'])."'
)")or die('Error:'.mysqli_error());
}
unset($_SESSION['carrito']);
header("Location:../admin.php");
?>
carritodecompras.php
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
<?php
session_start();
include 'conexion.php';
if(isset($_SESSION['carrito'])){
if(isset($_GET['id'])){
$arreglo=$_SESSION['carrito'];
$encontro=false;
$numero=0;
for($i=0;$i<count($arreglo);$i++){
if($arreglo[$i]['Id']==$_GET['id']){
$encontro=true;
$numero=$i;
}
}
if($encontro==true){
$arreglo[$numero]['Cantidad']=$arreglo[$numero]['Cantidad']+1;
$_SESSION['carrito']=$arreglo;
}else{
$nombre="";
$precio=0;
$imagen="";
$link = mysqli_connect("localhost", "root","","carrito de compras");
mysqli_select_db($link, "carrito de compras");
$tildes = $link->query("SET NAMES 'utf8'"); //Para que se muestren las tildes correctamente
$re = mysqli_query($link, "select * from productos where id=".$_GET['id'])or die(mysqli_error()
);
while ($f=mysqli_fetch_array($re)) {
$nombre=$f['nombre'];
$precio=$f['precio'];
$imagen=$f['imagen'];
}
$datosNuevos=array('Id'=>$_GET['id'],
'Nombre'=>$nombre,
'Precio'=>$precio,
'Imagen'=>$imagen,
'Cantidad'=>1);
array_push($arreglo, $datosNuevos);
$_SESSION['carrito']=$arreglo;
}
}
}else{
if(isset($_GET['id'])){
$nombre="";
$precio=0;
$imagen="";
$link = mysqli_connect("localhost", "root","","carrito de compras");
mysqli_select_db($link, "carrito de compras");
$tildes = $link->query("SET NAMES 'utf8'"); //Para que se muestren las tildes correctamente
$re = mysqli_query($link, "select * from productos where id=".$_GET['id'])or die(mysqli_error()
);
while ($f=mysqli_fetch_array($re)) {
$nombre=$f['nombre'];
$precio=$f['precio'];
$imagen=$f['imagen'];
}
$arreglo[]=array('Id'=>$_GET['id'],
'Nombre'=>$nombre,
'Precio'=>$precio,
'Imagen'=>$imagen,
'Cantidad'=>1);
$_SESSION['carrito']=$arreglo;
}
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8"/>
<title>Carrito de Compras</title>
<link rel="stylesheet" type="text/css" href="css/estilos5.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/scripts.js"></script>
</head>
<body>
<header>
<h1>Carrito de compras</h1>
<a href="carritodecompras.php" title="ver carrito de compras">
<img src="imagenes/carrito.png">
</a>
</header>
<section>
<?php
$total=0;
if(isset($_SESSION['carrito'])){
$datos=$_SESSION['carrito'];
$total=0;
for($i=0;$i<count($datos);$i++){
?>
<div class="producto">
<center>
<img src="data:image/jpeg;base64,<?php echo base64_encode($datos[$i]['Imagen']);?>"><br>
<span ><?php echo $datos[$i]['Nombre'];?></span><br>
<span>Precio: <?php echo $datos[$i]['Precio'];?></span><br>
<span>Cantidad:
<input type="text" value="<?php echo $datos[$i]['Cantidad'];?>"
data-precio="<?php echo $datos[$i]['Precio'];?>"
data-id="<?php echo $datos[$i]['Id'];?>"
class="cantidad">
</span><br>
<span class="subtotal">Subtotal:<?php echo $datos[$i]['Cantidad']*$datos[$i]['Precio'];?></span><br>
</center>
</div>
<?php
$total=($datos[$i]['Cantidad']*$datos[$i]['Precio'])+$total;
}
}else{
echo '<center><h2>No has añadido ningun producto</h2></center>';
}
echo '<center><h2 id="total">Total: '.$total.'</h2></center>';
if($total!=0){
echo '<center><a href="./compras/compras.php" class="aceptar">Comprar</a></center>;';
}
?>
<center><a href="./">Ver catalogo</a></center>
</section>
</body>
</html>
Valora esta pregunta


0