i have a problem with my php code, it gives me the error of : Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in C:\xampp\htdocs\funcion2.php on line 69
I dont know how to solve it. i need some help pls, i need to finish the project.
<?php
//Conexion a la BBDD
include 'config.php';
session_start();
if($_REQUEST['cur']){$_SESSION['cur2']=$_REQUEST['cur'];}
$cur=$_SESSION['cur2'];
$str=$cur;
$cur=explode ('|', $str);
echo $cur[0];
if ($_REQUEST['alu']){$_SESSION['alu2']=$_REQUEST['alu'];}
$alu=$_SESSION['alu2'];
$str2=$alu;
$alu=explode ('|', $str2);
/*primera consulta*/
$query = 'select * from curso';
$res=mysqli_query($conexion, $query);
/*segunda consulta*/
$query2 = 'select * from alumnos where cod_curso=$cur[0]';
$res2=mysqli_query($conexion, $query2);
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
</head>
<body>
<form name="form1" method="post">
<div class="form-group col-md-3">
<label>Curso</label>
<select name="cur" onchange="this.form.submit() ;">
<option value="<?php echo $cur[1] ?>" ></option>
<?php
while ($row=mysqli_fetch_array($res))
{
?>
<option value="<?php echo $row[0]."|".$row[1]?>"><?php echo htmlentities($row[1]); ?>
</option>
<?php } ?>
</select>
</div>
<div class="form-group col-md-6">
<label>Alumnos</label>
<select name="alu">
<option value="<?php echo $alu[0]?>"</option>
<?php
while ($value=mysqli_fetch_array($res2))
{
?>
<?php foreach ($alu as $key => $value){ ?>
<option value="<?php echo $value[0]."|".$value[1]?>"><?php echo htmlentities($value[1]);?>
</option>
<?php } ?>
<?php } ?>
</select>
</div>
<input type="submit" name="enviar" value="Enviar" hidden />
</form>
<?php
echo "Tu curso es: ".$cur[1]."<br/>";
echo "El alumno es: ".$alu[1]."<br/>";
?>
</body>
</html>
There is the problem .The error os mysql
My database have these 2 tables: Table alumnos and Table curso
I modified the parameters without @ and the second mysqli_fetch_array.
@operator. If something goes wrong you want to know about it and will need to take corrective action, display a useful message for the user, log the problem, or all that and more. It also makes debugging issues like this a whole lot more complicated if you ignore errors that are trying to point out serious problems.mysqliyou should be using parameterized queries andbind_paramto add user data to your query. DO NOT use string interpolation or concatenation to accomplish this because you have created a severe SQL injection bug. NEVER put$_POST,$_GETor any user data directly into a query, it can be very harmful if someone seeks to exploit your mistake.$value=mysqli_fetch_array($conexion, $cur)should be something more like$value=mysqli_fetch_array($res2)as it exppect 1st arg to be results, but i'm not posting this as an answer because both of @tadman comment should be taken into consideration before going any further.