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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:07:37+00:00 2026-05-12T23:07:37+00:00

I have a inefficiently constructed form that is obviously sending one type of data

  • 0

I have a inefficiently constructed form that is obviously sending one type of data per SELECT element. For simplicity’s sake, here’s an example.

The form posts data from 2 SELECT elements, but it actually needs to contain 3 pieces of data. To the user, the SELECTs do contain 3 pieces of data; one SELECT denotes quantity and the other SELECT denotes an item name AND a price using text between the OPTION tags.

So, the form is sending only $quantity and $itemname

In processing, I am trying to construct a bunch of IFs or a SWITCH to provide for the missing prices. Being that the string associated with $itemname is unique, I am trying to make a “key” that provides the price. My logic is, if $itemname contains “One Inch Nut” I could find for $price with something like:

if ($itemname = "Once Inch Nut;") { $price = .25; }

And if $itemname were something else, I would add another IF or IF else or CASE in a switch.

In fact, I am doing just that, yet when I select another OPTION from the SELECT, the $price and even the $item name are defined as the last “IF” in my stack of “IFs”

So if I were to select like, the 3rd item in a 20 item SELECT grouping, when it came time for me to use the variable (adding, echoing, whatever) I’d end up with the end of the “IF stack”

Obviously, my logic and understanding of IE ELSEIF ELSE is flawed.

Ideas on how to make this “Key” from a variable’s string data?

Thanks,
Rob

See below for an abridged example of what I thought would work:

Suppose the form posts “cat” for $itemname and “3” for $qty

<? 
$itemname =  $_POST['specificitem'] ;
$qty =  $_POST['quantity'] ;

if ($itemname = "cat;") { $price = 2.25; }
if ($itemname = "dog;") { $price = 1.25; }
if ($itemname = "hamster;") { $price = 3.25; }
if ($itemname = "parakeet;") { $price = 7.25; }
if ($itemname = "werewolf;") { $price = 122.25; }

echo $itemname; 
echo "$"$price;

?>

Should yield: cat $2.25 ????

  • 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-12T23:07:37+00:00Added an answer on May 12, 2026 at 11:07 pm

    You need == to test:

    if ($itemname == "cat;") { $price = 2.25; }
    

    However, it is common to see switch used for this type of situation:

    $itemname =  $_POST['specificitem'] ;
    $qty =  $_POST['quantity'] ;
    
    switch($itemname)
    {
      case "cat;":
        $price = 2.25;
        break;
      case "dog;":
        $price = 1.25;
        break;
      case "hamster;":
        $price = 3.25;
        break;
      case "parakeet;":
        $price = 7.25;
        break;
      case "werewolf;":
        $price = 122.25;
        break;
    }
    
    echo $itemname;
    echo "$"$price;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a structure called Patch that represents a 2D array of data. newtype
Have deployed numerous report parts which reference the same view however one of them
I'll just get right into it. I have a class User that needs to
We currently have a Stateful bean that is injected into a Servlet. The problem
I have a class that has more than a dozen properties. For most of
I have a Java programming lab-exercise in a course with students that I'd like
UPDATE: I now have a solution I'm much happier with that, whilst not solving
I have a json array that has multiple missing numbers and is out of
I have some large data sets (numeric and textual) and as I'm studying and
I have written a ListActivity class that uses a custom ArrayAdapter and Holders. I

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.