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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:27:47+00:00 2026-06-05T20:27:47+00:00

I am using mysqli to try and retrieve the teacher’s username and then insert

  • 0

I am using mysqli to try and retrieve the teacher’s username and then insert all of the values into the dataabse. The problem though is that nothing is being inserted into the database.

I am getting no errors in my error report so I think I am just doing something wrong when it comes to inserting values into the database using mysqli but I am not sure what. Can anybody give me any pointers on why it is not inserting values into the db?

Below is the code:

$username="xxx";
$password="xxx";
$database="mobile_app";

  $mysqli = new mysqli("localhost", $username, $password, $database);

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

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

$stmt=$mysqli->prepare($sql);
    // You only need to call bind_param once
$stmt->bind_param("s",$_SESSION['teacherusername']);

$stmt->execute(); 
$record = $stmt->fetch();
$teacherid = $record['TeacherId'];

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);

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


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

    $insert->execute();
}

$insert->close();

}
  • 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-05T20:27:49+00:00Added an answer on June 5, 2026 at 8:27 pm

    Try to debug this thing line by line:

    • set your error reporting to error_reporting(E_ALL); in php file or error_reporting = E_ALL in php ini
    • does the db connection work ?
    • echo the sql query before using it
    • it the query seems to be correct: rebuild it to ONE value and rebuild it step by step to find out where’s the error
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Mysqli OO to search the database for 2 specific values using the
I need to write a query to retrieve values from two columns using mysql
I have a serious problem. Firstly, I am trying to retrieve values from my
Here is the code I am using to try and retrieve an image from
I have made an application using Java/Hibernate/MySQL, but whenever I try running it, it
I'm using this code and I'm beyond frustration: try { $dbh = new PDO('mysql:dbname='
I just started using mysqli API for PHP. Apparently, every time an object of
I'm using MySQLi with PHP(5.2.4) MySQL(5.0.51a) on Ubuntu 8.04 LAMP. The relevant Db tables
I am using mysqli prepared statments and I am trying to write a prepared
I am using mysqli_stmt_bind_param() to create an INSERT statement. For some reason I am

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.