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 8115481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:29:43+00:00 2026-06-06T03:29:43+00:00

//connected to db if (isset($_POST[‘teacherusername’])) { $_SESSION[‘teacherusername’] = $_POST[‘teacherusername’]; } $sql = SELECT TeacherId

  • 0
 //connected to db

if (isset($_POST['teacherusername'])) {

$_SESSION['teacherusername'] = $_POST['teacherusername'];

}

        $sql = "SELECT TeacherId FROM Teacher WHERE (TeacherUsername = ?)";

        $stmt=$mysqli->prepare($sql);
        $stmt->bind_param("s",$_SESSION['teacherusername']);
        $stmt->execute();
        $record = $stmt->fetch();
        $teacherid = $record['TeacherId'];
        $stmt->close();




        if($_SERVER['REQUEST_METHOD'] == 'POST')

        {

        $time = str_replace(array(' Hrs ', ' Mins ', ' Secs'), array(':', ':', ''), $_SESSION['durationChosen']);

        $insertsql = "INSERT INTO Session (SessionId, SessionTime, SessionDate, SessionWeight, SessionDuration, TotalMarks, ModuleId, TeacherId, Room) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
        $insert = $mysqli->prepare($insertsql);

        for ($i = 1, $n = $_SESSION['sessionNum']; $i <= $n; ++$i) {
            $sessid = $_SESSION['id'] . ($n == 1 ? '' : $i);
            $sessdate = date("Y-m-d", strtotime($_SESSION['dateChosen']));

            $insert->bind_param("sssssssss", $sessid, $_SESSION['timeChosen'], $sessdate,
                             $_SESSION['textWeight'], $time, $_SESSION['textMarks'],
                             $_SESSION['module'], $teacherid, $_SESSION['rooms']);

            $insert->execute();

           if ($insert->errno) { echo "Error in insert: $insert->error<br>\r\n"; }

            $insert->close();
        }


        }

UPDATE:

The previous errors have been fixed, but I am now getting 4 warnings which are displayed below:

Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Couldn’t fetch mysqli_stmt in /web/stud/…/Mobile_app/insertsession.php on line 177

Warning: mysqli_stmt::execute() [mysqli-stmt.execute]: Couldn’t fetch mysqli_stmt in /web/stud/…/Mobile_app/insertsession.php on line 179

Warning: main() [function.main]: Couldn’t fetch mysqli_stmt in /web/stud/…/Mobile_app/insertsession.php on line 181

Warning: mysqli_stmt::close() [mysqli-stmt.close]: Couldn’t fetch mysqli_stmt in /web/stud/…/Mobile_app/insertsession.php on line 185

As that mysqli is now inserting data into the database, do I deal with these warnings or shall I leave them alone?

PROBLEM IS SOLVED, FOR FUTURE VIEWERS PLEASE LOOK AT DAVE RANDOM’S ANSWER

  • 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-06T03:29:44+00:00Added an answer on June 6, 2026 at 3:29 am

    Simply add this line at the end of your loop and it should work:

    $insert->close();
    

    This will work if you don’t still have an unclosed statement from code that is executed before the code you show. You must close the previous statement before another can be executed.

    See mysqli_stmt::close() for more information.

    EDIT

    Try this code:

    //connected to db
    
    $sql = "
      SELECT TeacherId
      FROM Teacher
      WHERE TeacherUsername = ?
    ";
    
    if (!$stmt = $mysqli->prepare($sql)) {
      // Handle errors with prepare operation here
    }
    
    // Bind parameter for statement
    $stmt->bind_param("s", $_SESSION['teacherusername']);
    
    // Execute the statement
    $stmt->execute();
    
    // This is what matters. With MySQLi you have to bind result fields to
    // variables before calling fetch()
    $stmt->bind_result($teacherid);
    
    // This populates $teacherid
    $stmt->fetch();
    
    // Close the statment
    $stmt->close();
    
    if($_SERVER['REQUEST_METHOD'] == 'POST')
    
    {
    
        $time = str_replace(array(' Hrs ', ' Mins ', ' Secs'), array(':', ':', ''), $_SESSION['durationChosen']);
    
        $insertsql = "
          INSERT INTO Session
            (SessionId, SessionTime, SessionDate, SessionWeight, SessionDuration, TotalMarks, ModuleId, TeacherId, Room)
          VALUES
            (?, ?, ?, ?, ?, ?, ?, ?, ?)
        ";
        if (!$insert = $mysqli->prepare($insertsql)) {
          // Handle errors with prepare operation here
        }
    
        for ($i = 1, $n = $_SESSION['sessionNum']; $i <= $n; ++$i) {
    
            $sessid = $_SESSION['id'] . ($n == 1 ? '' : $i);
            $sessdate = date("Y-m-d", strtotime($_SESSION['dateChosen']));
    
            $insert->bind_param("sssssssss", $sessid, $_SESSION['timeChosen'], $sessdate,
                         $_SESSION['textWeight'], $time, $_SESSION['textMarks'],
                         $_SESSION['module'], $teacherid, $_SESSION['rooms']);
    
            $insert->execute();
    
            if ($insert->errno) {
              // Handle query error here
            }
    
            $insert->close();
    
        }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is the code <?php session_start(); if(!isset($_SESSION['user_name'])) { header('Location: login.php'); } $conn = mysql_connect(localhost,
I have connected to local and server database from local SqlServer 2005. How to
Why wont this work? <?php include top.php; include connect.php; if(isset($_POST[submit])) { $error = ;
I need some help in converting my script from using mysql to mysqli I
<?php session_start(); include(connect.php); $timeout = 60 * 30; $fingerprint = md5($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']); if(isset($_POST['userName']))
<?php session_start(); if(isset($_POST['username']) && ($_POST['password'])) { $con=mysql_connect(localhost,root,); if(!$con) { die('Could Not Connect:'.mysql_error()); } mysql_select_db(tcs,$con);
<?php if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $dbhost = 'localhost'; $dbuser = 'zuk1_boo'; $dbpass
i have this situation: if(isset($_POST[sm]) { print <br><div id=\redirect\>success</div>; } in javascript i have:
I need a database for this: <?php if (isset($_POST['addcontentbox'])) { // Connection to Database
We are importing data from .sql script containing UTF-8 encoded data to MySQL database:

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.