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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:25:15+00:00 2026-05-16T16:25:15+00:00

if (isset ($_POST[‘somethingA’])) { //code for doing something A } elseif (isset ($_POST[‘somethingB’])) {

  • 0
 if (isset ($_POST['somethingA']))
 {
      //code for doing something A
 }
 elseif (isset ($_POST['somethingB']))
 {
      //code for doing something B
 }

I will need to access some data from somethingA code, into somethingB code.

How can I do that in a proper way?

Should I declare a variable outside the conditionals, work inside the conditionals, and later (bottom) I use that?

Should I work with them inside the conditionals, and, somehow, pull them out after the conditional lines?

Thanks in advance,
MEM

  • 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-05-16T16:25:16+00:00Added an answer on May 16, 2026 at 4:25 pm

    you may do something like you said:

    $innervar = null;
    
    if (isset ($_POST['somethingA']))
     {
          $innervar = new A();
          //code for doing something A
     }
     elseif (isset ($_POST['somethingB']))
     {
          $innervar = new B();
          //code for doing something B
         }
    
    $innervar->CommonMethod();
    

    If you are accesing $_POST directly consider using some sort of framework like symfony, or Zend, unless you are learning or working in a very simple(house) project.

    Best of luck
    David

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

Sidebar

Related Questions

I have the following code to escape posted data: if (isset($_POST['submitted'])) { $trimmed_post =
I have a little problem with my if(isset($_POST['submit'])) code. What I want is some
This is my php code: if (isset($_POST['data']) && is_array($_POST['data'])) { foreach ($_POST['data'] as $row
elseif(isset($_POST['submit'])) { // Look for their user $lookuser = mysql_query(SELECT * FROM `users` WHERE
Using the following code: if (isset($_POST['delete']) && isset($_POST['id'])) { $first = get_post('first'); $query =
I have come across scripts that use: isset($_POST['submit']) as well as code that uses:
I am trying to understand the difference between this: if (isset($_POST['Submit'])) { //do something
I am getting this error here is my code if(isset($_POST['submit'])) { $projTit=mysql_escape_string($_POST['projecttitle']); $projCat=mysql_escape_string($_POST['projectcategory']); $budget=intval(mysql_escape_string($_POST['budget']));
I am trying to get the following code to work: if (isset($_POST['file'])){ if(file_exists($_POST['file'])){ echo
I have something like: if(isset($_POST['submit'])) { $linktitle=strtolower(str_replace( ,-,$title)); etc. $linktitle and $title are actually

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.