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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:36:20+00:00 2026-06-13T08:36:20+00:00

I want to delete a session from a drop down menu. The user will

  • 0

I want to delete a session from a drop down menu. The user will select a session from the drop down menu and then click on the delete button, this should then delete session in the database. The problem is that if I click on the delete button, it then comes up with an undefined index errors stating sessionsDrop are undefined in line 200 My question is:

1: How can I get rid of the undefined index error in code below
2: How and where do you write the if statement so that if the deletion was successful, it will echo “Session … was Deleted” else if it hasn’t been delete then display echo “An error occured, Session … was not deleted”

Below is the code:

$sessionnum = 0;

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

     if($_REQUEST['modulesDrop']==''){

         echo "Please Select a Module from the Drop Down Menu Above";

     }
     else{  

 var_dump($_POST['modulesDrop']);

        $sessionquery = "
             SELECT SessionId, SessionDate, SessionTime, ModuleId
             FROM Session
             WHERE
             (ModuleId = ?)
             ORDER BY SessionDate, SessionTime 
            ";

$sessionqrystmt=$mysqli->prepare($sessionquery);
// You only need to call bind_param once
$sessionqrystmt->bind_param("s",$_POST['modulesDrop']);
// get result and assign variables (prefix with db)

$sessionqrystmt->execute(); 

$sessionqrystmt->bind_result($dbSessionId,$dbSessionDate,$dbSessionTime, $dbModuleId);

 $sessionqrystmt->store_result();

$sessionnum = $sessionqrystmt->num_rows();   

    $dataArraySession = array();

 while ( $sessionqrystmt->fetch() ) { 

 $dataArraySession[$dbSessionId]['SessionDate'] = $dbSessionDate; 
 $dataArraySession[$dbSessionId]['SessionTime'] = $dbSessionTime;

}

   $sessionHTML = "";
   $sessionHTML .= '<select name="session" id="sessionsDrop">'.PHP_EOL;
   $sessionHTML .= '<option value="">Please Select</option>'.PHP_EOL;     

foreach ($dataArraySession as $sessionId => $sessionData) {

   $sessionHTML .= "<option value='$sessionId'>" . $sessionId . " - " . $sessionData['SessionDate']. " - " . $sessionData['SessionTime'] ."</option>".PHP_EOL;        

        }

   $sessionHTML .= '</select>';
}
 if ($sessionnum > 0) {

 ?>

     <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
     <p>Sessions: <?php echo $sessionHTML; ?><input id="sessionSubmit" type="submit" value="Delete" name="sessionsubmit" /></p>      
    </form>       

<?php

}
else {
 echo "<p>Sorry, You have No Sessions under this Module</p>";
}

}

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

     if($_REQUEST['sessionsDrop']==''){ //line 200 where undefined index occurs

         echo "Please Select a Session from the Drop Down Menu Above to Delete a Session";

     }
     else{  

 var_dump($_POST['sessionsDrop']);

 $sessiondel = $_POST['sessionsDrop'];

         $sessiondeletesql = " DELETE sess 
        FROM Session AS sess 
        WHERE sess.SessionId = ?"; 


                if (!$delete = $mysqli->prepare($sessiondeletesql)) {
      // Handle errors with prepare operation here
    }

    //Dont pass data directly to bind_param store it in a variable
$delete->bind_param("s", $sessiondel);

 $delete->execute();

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

        $delete->close();

        echo "Session $sessiondel was Deleted";
}
}
    ?>
  • 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-13T08:36:21+00:00Added an answer on June 13, 2026 at 8:36 am

    Your undefined index error is because you are using $_REQUEST['sessionsDrop']=='', but your form code is –

    $sessionHTML .= '<select name="session" id="sessionsDrop">'.PHP_EOL;
    

    So you should use $_REQUEST['session']=='', instead of $_REQUEST['sessionsDrop']=='' since the super globals ($_POST, $_GET, $_REQUEST) reference the name, not the id.

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

Sidebar

Related Questions

I want to delete all the elements from my list: foreach (Session session in
I want to delete an array index from an array, then reload listView with
How can I access a user session objects from another thread? I want to
I want to delete all rows in a datatable. I use something like this:
I want to delete DataRows from a DataTable. The rows to be deleted are
I want to delete an entry from my Database but it says it can't
I want to delete a file into recycle bin. I using this code. SHFILEOPSTRUCT
I want to delete a number of jobs from a q. The command to
I want to delete files from a specific directory recursively. So, I have used
I want to delete data from a mysql table if its with current date.

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.