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

The Archive Base Latest Questions

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

I had an old mysql code where it successfully inserted values into the database.

  • 0

I had an old mysql code where it successfully inserted values into the database. But as that people are now stating that mysqli is better to use (can’t use PDO because of my version of php is below 5.3), I have tried to change my code so that it uses mysqli instead of mysql.

The problem is that it now does not insert values into the database since making this change. I am a mysqli novice so I would really appreciate it if somebody can help me change the code below so that mysqli can be used to insert data into the database. What am I doing wrong? There are no errors in the error report.

Below is my current attempt on this:

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


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


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

    Looks like you’re missing the ending quote on this line:

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

    Make it

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

    It also looks like you need to put your for loop before you bind the params, since you’re using the results of said for loop in the bind.

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

Sidebar

Related Questions

I had old code that the source got lost (but we own it) so
I updated my User class, and now whenever someone that had the old version
I had this working in an old code that I didn’t end up using...
I had an old instalation of MySQL but it wasn't working very well.. so
I had an old (but great) app using NHibernate 1.0.2. Worked like a charm.
I'm currently working on a large and old C++ application that has had many
Had a good search here but can't see anything that gets my mind in
Had a problem with the recursive conflictCheck() method. That seems fine now. I have
We previously had a database in MySQL. In it, we had a table called
I had old phone with one interesting functionality, that was ability to turn on

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.