jeudi 10 août 2017

Collect two values including a foreach loop and enter to the database, how does it works?

actually I create a fitnesstool that allows you to you safe your daily workout to a database. There is one page where the workout will be shown, and another page, where you can enter the values of the daily workout.

Two values must be collected:

  • the fitnessplan, who is safed at the database fitnessplans
  • the values where entered by the form (collected with foreach)

While collecting the stations of the fitnessplan I get a problem. Only one station of the fitnessplan is collected, but the values of the form were complete ond correct collected.

It seems as if the while-loop starts only once, then the foreach-loop is starting but the while-loop isn't starting again.

$sql = $db->query("SELECT * FROM fitnessplans WHERE uid='$sess_id'");
   if($sql->num_rows != 0) {
       while($row = mysqli_fetch_assoc($sql)) {
           $content = $row['content'];

           foreach ($mass as $elem1) {
           if(!empty($elem1)) {
               $sql = $db->query("INSERT INTO sessions (uid,content,value,datetime) VALUES ('$sess_id','$content','$elem1',$time)");
          } 
           header("Location: index.php#trainings");
       }
    }   
}

Aucun commentaire:

Enregistrer un commentaire