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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:26:25+00:00 2026-06-15T15:26:25+00:00

I would like to get user values from an HTML form to an array

  • 0

I would like to get user values from an HTML form to an array and then insert it into a mysql database. it insert correct values into the database, then it gives out the following error:

Notice: Undefined index: TopicNum in C:\wamp\www\Capturing System\All_Topics_widget.php on line 153

The following is right at the top of the page:

<?php 
include 'scripts/functions/init.php';
Restrict();

?>

$userid = $_SESSION['userid'];
$KM_Number = $_SESSION['C_KM'];
$query = "SELECT * FROM knowledge_modules where km_number = "."'".$KM_Number."'";
$Knowledge = mysql_query($query) or die(mysql_error);
$row = mysql_fetch_assoc($Knowledge);
$Module_type = 'Knowledge Modules';
$Purpose_M = $_SESSION['Purpose_KM'];
$KM = 'KM';
$NUM = $_SESSION['KM'];
$KT = 'KT';

if (empty($_POST)=== false)
    {
        $R_fields = array('Topic_Num','Title','Weight');
        foreach($_POST as $key=>$value)
        {
            if (empty($value) && in_array($key,$R_fields)=== true)
                {
                    $errors[] = 'fields marked with (*) are required';
                    break 1;
                }
        }

        if(empty($errors)=== true)
            {
                if(topic_exists($_POST['TopicNum']))
                    {
                        $errors[] = 'Sorry, the Topic already exist!';
                    }


            }
    }

?>
The following code is within the HTML Tags:

<h2>Tools - </h2>

            <form action="All_Topics_widget.php" method="POST" enctype="multipart/form-data">
              <fieldset>
                <table border="0">
                    <tr>
                        <td><label for="TopicNum">Topic Number:*&nbsp<?php echo $KM.'-'.$NUM.'-'.$KT ?></label></td>
                        <td><input type="text" size="5" name="TopicNum" /></td>
                    </tr>
                    <tr>
                        <td><label for="Title">Title:*</label></td>
                        <td><input type="Text" size="35" name="Title"/></td>
                    </tr>
                    <tr>
                        <td><label for="Weight">Weight:*</label></td>
                        <td><input type="text" size="05" name="Weight" /></td>

                    </tr>

                </table>
            </fieldset>
              <fieldset>
                       <table border="0">
                            <tr>
                                <td><input id="Submit" type="submit" value="Capture" /></td>
                                <td><input id="Reset1" type="reset" value="reset" /></td>
                                 <td><a href="list_topics.php">Capture Topics</a></td>

                           </tr>
                        </table>
              </fieldset>
              <?php

                    $Topics = $KM.'-'.$NUM.'-'.$KT.$_POST['TopicNum'];//This is line 153
                    if(isset($_GET['success']) && empty($_GET['success']))
                        {
                            echo 'Succefully Captured';
                        }
                    else
                        {
                            if(empty($_POST) == false && empty($errors)== true)
                                {

                                    //Capture data from the fields to an array
                                    $capture_topic = array(
                                    'TopicNum' => $Topics,
                                    'Title'=>$_POST['Title'],
                                    'Weight'=>$_POST['Weight'],
                                    'Purpose_M'=>$Purpose_M,
                                    'userid'=>$userid);                                     

                                    //Submit the data into the database
                                    capture_topic($capture_topic);
                                    //redirect to the Modules widget page till the user press NEXT Page
                                    header('Location: All_Topics_widget.php?success');
                                    exit();

                                }

                            else if(empty($errors)== false)
                                {
                                    //Display errors

                                    echo output($errors);
                                }
                        }

              ?>
       </form>
  • 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-15T15:26:27+00:00Added an answer on June 15, 2026 at 3:26 pm

    This Notice is appearing because you are referencing $_POST['TopicNum'] on line 153, when this $_POST[] variable is no longer set.

    Try moving line 153 inside if(empty($_POST) == false && empty($errors)== true) {}

     if(empty($_POST) == false && empty($errors)== true)
            {
            $Topics = $KM.'-'.$NUM.'-'.$KT.$_POST['TopicNum'];//This is line 153
             ...
             }
    

    Here is why it is causing the Notice –

    1=> You submit/POST the form, thus setting $_POST['TopicNum'] and used on line 153.
    2=>You input the values into the database on line 172 capture_topic($capture_topic);
    3=>You redirect to the page on 174 header('Location: All_Topics_widget.php?success');, thus clearing the $_POST[] globals, so when it is called again on 153 it is now undefined. by moving it inside your check for if(empty($_POST) == false && empty($errors)== true) it will only be reference when the form has been submitted/POSTed

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

Sidebar

Related Questions

I would like to encode user input values coming from a web interface in
I would like to get the address string of the current user location. Is
I would like to know what events get executed (if any) after a user
I would like to get numbers of comments for each posts using mysql. I
I would like to get a help from you all. The below is the
I'm facing a simple problem I would like to get a local path from
I have been trying to get a form in HTML/PHP to process to into
In a HTML form, how can I get two names from one input field?
I would like to get to know how to redirect output of some program
I would like to get View instance that is used to display specific Preference

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.