Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9113739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:02:03+00:00 2026-06-17T04:02:03+00:00

I cannot seem to figure it out but I am getting an error in

  • 0

I cannot seem to figure it out but I am getting an error in my php/mysqli stating:

Warning: Invalid argument supplied for foreach() in
/…/ on line 28

My question is that how can the above warning be fixed so that I can loop over the insert to be able to provide all of the inserts into the db:

<?php

ini_set('display_errors',1); 
 error_reporting(E_ALL);

 // connect to the database
 include('connect.php');

  /* check connection */
  if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    die();
  }

$studentid = (isset($_POST['addtextarea'])) ? $_POST['addtextarea'] : ''; 
$sessionid = (isset($_POST['Idcurrent'])) ? $_POST['Idcurrent'] : '';   

$insertsql = "
INSERT INTO Student_Session
(SessionId, StudentId)
VALUES
(?, ?)
";
if (!$insert = $mysqli->prepare($insertsql)) {
// Handle errors with prepare operation here
}                                       

foreach($studentid as $id)
{    

$insert->bind_param("ii", $sessionid, $id);

$insert->execute();

if ($insert->errno) {
// Handle query error here
}

}

$insert->close();

$query = "SELECT ss.SessionId, SessionName, StudentId
FROM  
Student_Session ss
INNER JOIN Session s ON
ss.SessionId = s.SessionId
WHERE ss.SessionId = ? AND StudentId = ?";
// prepare query
$stmt=$mysqli->prepare($query);
// You only need to call bind_param once
$stmt->bind_param("ii", $sessionid, $studentid);
// execute query
$stmt->execute(); 
// get result and assign variables (prefix with db)
$stmt->bind_result($dbSessionId, $dbSessionName, $dbStudentId);
//get number of rows
$stmt->store_result();
$numrows = $stmt->num_rows();
//fetch the results
$stmt->fetch();

if ($numrows == 1){

echo json_encode(array('errorflag'=>false,'msg'=>"Students have been successfully added into the Assessment"));

}else{

echo json_encode(array('errorflag'=>true,'msg'=>"An error has occured, Students have not been added into the Assessment"));

}

        ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:02:04+00:00Added an answer on June 17, 2026 at 4:02 am

    Your conditional where $studentid is set can set the value to an empty string. You should probably have some conditional in there to not even attempt to prepare as statement and insert data in such a case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cannot seem to figure out I am getting the following error in IE
I'm using MacVim as my primary code editor but cannot seem to figure out
Im trying to join two tables but cannot seem to figure out how to
I cannot seem to figure out how to always round up in PHP. ceil()
Looking over the magento 1.5 schema I cannot seem to figure out how a
I cannot figure out this positioning problem in Firefox. It doesn't seem to follow
I'm working on a class project and I cannot seem to figure out what
I'm having a small issue that I cannot seem to figure out. I am
I cannot seem to figure out how to do a Selection Alignment in the
i am currently using the RestClient and cannot seem to figure out how to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.