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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:32:28+00:00 2026-06-15T19:32:28+00:00

Below I have a modules drop down menu where it gets a list of

  • 0

Below I have a modules drop down menu where it gets a list of modules from the db an obviously displays them in a drop down menu. It also displays the selected module number and module name in the $output variable and in a hidden input ($hiddenoutput) it displays the module id of the selected module (This was successfully texted when text input was text before changing to hidden)

$active = 1;

 $sql = "SELECT ModuleId, ModuleNo, ModuleName FROM Module WHERE ModuleActive = ? ORDER BY ModuleNo"; 

 $sqlstmt=$mysqli->prepare($sql);

 $sqlstmt->bind_param("i",$active);

 $sqlstmt->execute(); 

 $sqlstmt->bind_result($dbModuleId, $dbModuleNo, $dbModuleName);

 $modules = array(); // easier if you don't use generic names for data 

 $output = ""; 
 $hiddenoutput = "";
 $moduleHTML = "";  
 $moduleHTML .= '<select name="module" id="modulesDrop">'.PHP_EOL;
 $moduleHTML .= '<option value="">Please Select</option>'.PHP_EOL;  

 while($sqlstmt->fetch()) 
 { 
     $moduleno = $dbModuleNo;
     $module = $dbModuleId;
     $modulename = $dbModuleName; 
     $moduleHTML .= "<option value='".$module."'>" . $moduleno . " - " . $modulename . "</option>".PHP_EOL;  

         if (isset($_POST['module']) && ($_POST['module'] == $module)) {
    $output .= "<p><strong>Selected Module:</strong> " . $moduleno .  " - "  . $modulename . "</p>";
    $hiddenoutput .= "<p><input type='hidden' id='hiddenoutput' name='hiddenmodule' value='". $module ."'></p>";
}
  } 

  $moduleHTML .= '</select>'; 

  $submittedModuleId = (isset($_POST['module'])) ? $_POST['module'] : '';
  $output = (isset($output)) ? $output : '';
  $hiddenoutput = (isset($hiddenoutput)) ? $hiddenoutput : '';

The details are displayed in the form below:

<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<table>
<tr>
<th>Module: <?php echo $moduleHTML; ?><input id="moduleSubmit" type="submit" value="Submit" name="submit" /></th>
</tr>
<tr>
<td><span id="errormsg"><?php echo $errormsg; ?></span><?php echo $hiddenoutput . $output; ?></td>
</tr>
</table>
</form>

But what I really do not understand is that in my INSERT sql below, it is able to retrieve and insert all values except for one and that is the value of the Module Id displayed in the hidden input. It keeps stating:

Warning: mysqli_stmt::execute(): (23000/1048): Column 'ModuleId' cannot be null in ... on line 172

What my question is that why is can not it retrieve and insert the value in the database for the module id? Below is the code:

session_start();

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

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

}

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

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

}

if(isset($_POST['sessionNum'])){
            //Declare my counter for the first time

            $_SESSION['initial_count'] = $_POST['sessionNum'];
            $_SESSION['sessionNum'] = $_POST['sessionNum'];

    }

if (!isset($_SESSION['sessionCount'])) {
    $_SESSION['sessionCount'] = 1;
}
else if ($_SESSION['sessionCount'] < $_SESSION['sessionNum']) {
    ++$_SESSION['sessionCount'];
}


$sessionMinus =  $_SESSION['sessionCount'];

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

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

}

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

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

}

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

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

}

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

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

}

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

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

}

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

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

}

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

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

}

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

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

}

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

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

}

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

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

}

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

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

}

var_dump($_POST);
var_dump($_SESSION);

 // connect to the database
 include('connect.php');

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

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

    for ($i = 1, $n = $_SESSION['sessionNum']; $i <= $n; $i++) {

            $insertsql = "
      INSERT INTO Session
        (SessionName, SessionTime, SessionDate, SessionWeight, SessionDuration, TotalMarks, ModuleId, TeacherId, Room)
      VALUES
        (?, ?, ?, ?, ?, ?, ?, ?, ?)
    ";
    if (!$insert = $mysqli->prepare($insertsql)) {
      // Handle errors with prepare operation here
    }

        $sessname = $_SESSION['id'] . ($n == 1 ? '' : $i);
        $sessdate = date("Y-m-d", strtotime($_SESSION['dateChosen']));

        $insert->bind_param("sssisiiis", $sessname, $_SESSION['timeChosen'], $sessdate,
                     $_SESSION['totalWeight'], $time, $_SESSION['textMarks'],
                     $_SESSION['hiddenmodule'], $teacherid, $_SESSION['rooms']);

        $insert->execute();

        if ($insert->errno) {
          // Handle query error here
        }

        $insert->close();

    }


}

Below is what the var_dump($_SESSION) outputs:

array(17) { 
["teacherid"]=> int(49) 
["teacherusername"]=> string(8) "u0867587" 
["teacherforename"]=> string(5) "Bruce" 
["teachersurname"]=> string(5) "Finch" 
["id"]=> string(5) "XNTLR" 
["initial_count"]=> string(1) "1" 
["sessionNum"]=> string(1) "1" 
["sessionCount"]=> int(1) 
["durationChosen"]=> string(22) "02 Hrs 00 Mins 00 Secs" 
["dateChosen"]=> string(10) "15-12-2012" 
["timeChosen"]=> string(5) "10:00" 
["textQuestion"]=> string(1) "1" 
["textMarks"]=> string(1) "5" 
["totalWeight"]=> string(1) "0" 
["buildings"]=> string(14) "Canalside East" 
["rooms"]=> string(7) "CE01/04" 
["hiddenmodule"]=> NULL }
  • 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-15T19:32:29+00:00Added an answer on June 15, 2026 at 7:32 pm

    Because hiddenmodule is is not posted. See your var dump. Check the form with firebug to see if this input field is add

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

Sidebar

Related Questions

Below I have a modules drop down menu where it gets a list of
Below I have a php script where it displays a Course drop down menu
Below I have a php script where it displays a Course drop down menu
I have php/mysqli and jquery code below where it displays a course drop down
I have dropdown menu below where it retrieves the possible modules id's and their
In my code below I have 2 drop down menus. One is a Course
I have created a module in Flex like below: modules/ModuleBase.mxml <?xml version=1.0 encoding=utf-8?> <mx:Module
I have this code below in the module.php script where it displays options in
I have a rails module included for reference below that I have included using
I have made a YUI module a little like the code shown below, which

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.