I have the next problem:
My code is this one:
$id=$_SESSION["id"];
$query="select id_period from periods where id_group=$id and end=NULL";
$result=mysqli_query($conn,$query);
if(mysqli_num_rows($result)==0){
$insert=mysqli_query($conn,"insert into periods(id_group) values($id)");
}
while($row=mysqli_fetch_row($result)){
$period=$row['id_period'];
}
$query="insert into times(id_period,id_group) values($period,$id)";
echo $query;
$insert=mysqli_query($conn,$query);
This code should search if exists a 'period' with field 'end'=NULL. If not, then insert a new one. That works fine. However, the next part doesn't working. The insert into 'times' query needs the id_period, given by the var $period, but the WHILE never runs.
Any idea? Thank you.
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.