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

  • Home
  • SEARCH
  • 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 8601273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:48:16+00:00 2026-06-12T01:48:16+00:00

I have a mysqli/php code below where it is suppose to insert data into

  • 0

I have a mysqli/php code below where it is suppose to insert data into the ‘Session’ Table. Now it used to insert data with no problems previously and I have not changed the code below:

if($_SERVER['REQUEST_METHOD'] == 'POST')        
{        
    $time = str_replace(array(' Hrs ', ' Mins ', ' Secs'), 
               array(':', ':', ''), $_SESSION['durationChosen']);        
    for ($i = 1, $n = $_SESSION['sessionNum']; $i <= $n; ++$i) 
    {               
            $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
    }        
        $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();        
    } 
}

Like I said this code worked before and I have not changed anything in the code since. But I cannot remember if its because I change the table in the database (phpmyadmin) that it is not inserting data into the database.

Can anyone check the Table creation before and state if you see any problems? Could the problem be with other tables which contains SessionId as their foriegn key?

Below is the Table Creation using SHOW CREATE TABLE Session:

CREATE TABLE `Session` (
 `SessionId` varchar(10) NOT NULL,
 `SessionTime` time NOT NULL,
 `SessionDate` date NOT NULL,
 `SessionWeight` int(3) NOT NULL,
 `SessionDuration` time NOT NULL,
 `TotalMarks` int(5) NOT NULL,
 `FileId` varchar(10) DEFAULT NULL,
 `ModuleId` varchar(10) NOT NULL,
 `TeacherId` int(4) NOT NULL,
 `Room` varchar(10) NOT NULL,
 PRIMARY KEY (`SessionId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
  • 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-12T01:48:18+00:00Added an answer on June 12, 2026 at 1:48 am

    Based on the information you are giving us, we have to make the following assumptions:

    • Your logic flow is correct and we are making it inside the if and for loops
    • The $_SESSION variable has all the keys you are claiming

    With those assumptions the variable $teacherId is not being set, so it’s value is null. In your table create statement the TeacherID column does not accept a null value so the insert is failing.

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

Sidebar

Related Questions

I have a mysqli/php code below where it is suppose to insert data into
I have a block of code below which inserts data into database using mysqli
I have a mysqli code below where it uploads a file and insert data
Here my code, I need to insert into mysql database I have mysql,php,android 1)
I have the php webservice code below, what I am suppose to do, so
I have piece of code (imageupload.php) below where the php is suppose to upload
Suppose that I have the PHP code as below: class modual { public $glo;
Suppose that I have the code php as below: <?php include(connectdb.php); $check1 = ;
Possible Duplicate: php/Mysql query with inserting date fails I have a datepicker code below:
I have PHP code which connects to MySql and encodes data to JSON. Later

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.