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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:40:21+00:00 2026-06-17T20:40:21+00:00

from a HTML from users can select subjects under different categories. after selected subjects

  • 0

from a HTML from users can select subjects under different categories. after selected subjects I have save them on session. Its OK. I did it like this…

$_SESSION['select-subjectes'] = $_POST['select-subjectes']; 

This is the result of echo '<pre>', print_r($_SESSION['select-subjectes']), '</pre>';

    Array
(
    [Grade 5 (Scholarship Exam)] => Array
        (
            [0] => 3:2
            [1] => 3:3
        )

    [Grade 11 (O/L)] => Array
        (
            [0] => 5:8
            [1] => 5:10
        )

    [Graduation Level] => Array
        (
            [0] => 7:24
            [1] => 7:46
            [2] => 7:82
        )

)

Now I need to get this values to insert to the database. 3:2 this kind of value mean is the number before colon are category ids and the number after colon are subject ids. My problem is when I try to get this values respectively to insert to the database.

I tried something like this.. but its not working..

if ( isset($_SESSION['select-subjectes'])) {                        
    $data = array();
    $data = $_SESSION['select-subjectes'];

    foreach($data as $key => $value) {

        $pieces = explode(":", $value);
        $catId = $pieces[0];
        $subId = $pieces[1];

        $q = "INSERT INTO category_subject ( category_id, subject_id ) VALUES ( ?, ? )";            
        $stmt = mysqli_prepare( $dbc, $q );         
        mysqli_stmt_bind_param( $stmt, 'ii', $catId, $subId );          
        mysqli_stmt_execute( $stmt ); 
    }       
}

Hope someone help me out about this..
Thank you.

  • 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-17T20:40:22+00:00Added an answer on June 17, 2026 at 8:40 pm

    you have to do two foreach loops on it like this:

    foreach($data as $array){
     foreach($array as $key => $value) {
    
            $pieces = explode(":", $value);
            $catId = $pieces[0];
            $subId = $pieces[1];
    
            $q = "INSERT INTO category_subject ( category_id, subject_id ) VALUES ( ?, ? )";            
            $stmt = mysqli_prepare( $dbc, $q );         
            mysqli_stmt_bind_param( $stmt, 'ii', $catId, $subId );          
            mysqli_stmt_execute( $stmt ); 
        }     
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a website in which the users can select a value from
I have a select element from which the users can select a value and
In a Rails app I have Users who can have notes created under them
I have a simple ASP.NET page that users can browse to, select a file
I have a listbox that users can add/remove from. To add, there's a text
I have an HTML page that uses AJAX to retrieve messages from a server.
I have an HTML textarea element. I want to prevent a user from entering
My problem comes from HTML dropdown select not able to preserve multiple consecutive whitespaces
I am getting some unexpected behavior from Html.EditorFor(). I have this controller: [HandleError] public
I need to let users select an item from a dropdown list, but also

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.