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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:31:37+00:00 2026-06-12T03:31:37+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.

  ...

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

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

}

...

        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("sssisisis", $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();

            }

Problem I am getting is that it is not inserting any data into the database and the reason for this is because it is displaying this error below:

Warning: mysqli_stmt::execute(): (23000/1048): Column 'SessionWeight' cannot be null in /web/stud/..../.... on line 182

The values posted into the “SessionWeight” column comes from $_SESSION['textWeight'] But it should not display this error because I have stated that if user has clicked on “No” in the radio button below, then the value in the textbox is 0, else if the user selects “Yes” then the user must enter in their own figure (blank textbox not allowed).

//HTML
        <th>Provide a Total Weight Assessment is worth to Module?</th>
        <td><input type="radio" name="weightChoice" value="Yes" onClick="getWeight()" class="radioBtn"/> Yes</td>
            <td><input type="radio" name="weightChoice" value="No" onClick="getWeight()" class="radioBtn"/> No</td>
            </tr>
            </table>
            <div id="radioAlert"></div>
            <p></p>
        <table id="tblWeight">
        <tr>
        <th>Weight:</th>
            <td><input type="text" id="txtWeight" name="totalWeight" onkeypress="return isNumberKey(event)" maxlength="5" />%</td>
            </tr>
            </table>

….

//Javascript

        function getWeight() {
            var weightChoice = document.getElementsByName("weightChoice");               
            var textWeight = document.getElementById("txtWeight");
            var tblWeight = document.getElementById("tblWeight");

            if(weightChoice[0].checked == true){
                tblWeight.style.display = "block";
                textWeight.value = "";
            }else{
                tblWeight.style.display = "none";
                textWeight.value = 0;

        }

    }

The SessionWeight column in the database is a non-key field which data type is int(3)

  • 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-12T03:31:38+00:00Added an answer on June 12, 2026 at 3:31 am

    Your input field has name="totalWeight", but you try to read $_POST['textWeight']

    It looks like that’s the problem

    • 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.