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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:36:17+00:00 2026-06-15T19:36:17+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:

$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 = ""; 
 $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>";
}
  } 

  $moduleHTML .= '</select>'; 

But the problem I am getting below is that when I try to insert the selected module into the database, it is unable to do it and hence ModuleId is null. Why can it not insert the selected module into the database?

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

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

}

if($_SERVER['REQUEST_METHOD'] == 'POST')

{



            $insertsql = "
      INSERT INTO Session
        (ModuleId)
      VALUES
        (?)
    ";
    if (!$insert = $mysqli->prepare($insertsql)) {
      // Handle errors with prepare operation here
    }


        $insert->bind_param("i", $_SESSION['module']);

        $insert->execute();

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

        $insert->close();



}

ModuleId is an INT field

  • 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:36:18+00:00Added an answer on June 15, 2026 at 7:36 pm

    try this

        if ($insert = $mysqli->prepare($insertsql)) {
    
    
        $insert->bind_param("i", real_escape_string($_SESSION['module']));
    
        $insert->execute();
        $insert->close();
        }
        else  {
          // Handle query error here
        }
    
    • 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 2 modules. Each contains a Sub with the same name. See below:
I have a jquery code below where an option which has been selected from
i have a youtube embedded channel from a certain company, and below i have
I have a Python 3 project where I'm dynamically importing modules from disk, using

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.