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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:36:22+00:00 2026-06-03T02:36:22+00:00

I have a form that has 3 types of field: (2) text fields that

  • 0

I have a form that has 3 types of field:

  1. (2) text fields that submit to “tblCocktail”
  2. (4) select fields that are populated with values from “tblIngredient”
    and submit to “tblRecipe”
  3. (4) select fields with pre-set options that submit to “tblRecipe”

Form Code (There are 4x of each “selectingred” & “quantity” drop-downs):

<form method="POST" action="addcocktail.php" >
                    Cocktail Name: <input type="text" name="cocktailname" /> 
                    How To: <input type="text" name="howto" /> 
                    <br> 
                    <select id="selectingred1" name="selectingred1">
                      <?php
                      $sql = "SELECT ingredientID, name FROM tblIngredient ".
                      "ORDER BY name";

                      $rs = mysql_query($sql);

                      while($row = mysql_fetch_array($rs))
                      {
                        echo "<option value=\"".$row['ingredientID']."\">".$row['name']."</option>\n  ";
                      }
                      ?>
                    </select>
                    <select id="quantity1" name="quantity1">
                      <option></option>
                      <option>1</option>
                      <option>2</option>
                      <option>3</option>
                      <option>4</option>
                    </select>
                    <br>
<input type="submit" value="add" />
                </form>

addcocktail.php:

 <?php include("databasecon.php"); ?>

<?php
mysql_select_db("mwheywood", $con);

//insert cocktail details
$sql="INSERT INTO tblCocktail (name, howto)
VALUES
('$_POST[cocktailname]','$_POST[howto]')";

$sql2="INSERT INTO tblRecipe (ingredientID, quantity)
VALUES
('$_POST[selectingred1]','$_POST[quantity1]'),
('$_POST[selectingred2]','$_POST[quantity2]'),
('$_POST[selectingred3]','$_POST[quantity3]'),
('$_POST[selectingred4]','$_POST[quantity4]')";



if (!mysql_query($sql,$con))
  {
  die('Error: you fail at life' . mysql_error());
  }
echo "cocktail added";

if (!mysql_query($sql2,$con))
  {
  die('Error: you fail at life' . mysql_error());
  }
echo "ingredients added";

mysql_close($con);

?>

This is currently only adding the “selectingred4” and “quantity4” values into “tblRecipe”. It’s ignoring the two inserts for the text boxes, and the first 3 select box entries.

My other problem was also that Im grabbing the “ingredientID” and “name” from the php in my form, but when I submit the form it’s not submitting “ingredientID” into “tblRecipe” either.

-any help would be appreciated -Matt

  • 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-03T02:36:24+00:00Added an answer on June 3, 2026 at 2:36 am

    You keep overwriting your SQL query and only the last one actually exists to be executed. Here’s a fixed version of your code:

    <?php include("databasecon.php"); ?>
    
    <?php
    mysql_select_db("mwheywood", $con);
    
    //insert cocktail details
    $sql="INSERT INTO tblCocktail (name, howto)
    VALUES
    ('$_POST[cocktailname]','$_POST[howto]')";
    
    if (!mysql_query($sql,$con))
    {
    die('Error: you fail at life' . mysql_error());
    }
    
    //insert recipe details
    $sql="INSERT INTO tblRecipe (ingredientID, quantity)
    VALUES
    ('$_POST[selectingred1]','$_POST[quantity1]')";
    
    $sql="INSERT INTO tblRecipe (ingredientID, quantity)
    VALUES
    ('$_POST[selectingred2]','$_POST[quantity2]')";
    
    $sql="INSERT INTO tblRecipe (ingredientID, quantity)
    VALUES
    ('$_POST[selectingred3]','$_POST[quantity3]')";
    
    $sql="INSERT INTO tblRecipe (ingredientID, quantity)
    VALUES
    ('$_POST[selectingred4]','$_POST[quantity4]')";
    if (!mysql_query($sql,$con))
      {
      die('Error: you fail at life' . mysql_error());
      }
    echo "cocktail added";
    
    mysql_close($con);
    
    ?>
    

    Furthermore, you can combine the last four queries into one query:

    <?php include("databasecon.php"); ?>
    
    <?php
    mysql_select_db("mwheywood", $con);
    
    //insert cocktail details
    $sql="INSERT INTO tblCocktail (name, howto)
    VALUES
    ('$_POST[cocktailname]','$_POST[howto]')";
    
    if (!mysql_query($sql,$con))
    {
    die('Error: you fail at life' . mysql_error());
    }
    
    //insert recipe details
    $sql="INSERT INTO tblRecipe (ingredientID, quantity)
    VALUES
    ('$_POST[selectingred1]','$_POST[quantity1]'),
    ('$_POST[selectingred2]','$_POST[quantity2]'),
    ('$_POST[selectingred3]','$_POST[quantity3]'),
    ('$_POST[selectingred4]','$_POST[quantity4]')";
    if (!mysql_query($sql,$con))
      {
      die('Error: you fail at life' . mysql_error());
      }
    echo "cocktail added";
    
    mysql_close($con);
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple login form that has 2 text fields and a button.
I have a simple contact form on a website that has 2 text fields,
I have a form that has fields with the following name <input type=text name=value[]>
I have a form that has multiple fields, and for testing purposes is there
i have a form that has a multiple select drop down. a user can
I have created a contact form that has a disabled submit button until all
I'd like to have a single form that has 2 or more field-set_tags and
I have a index.jsp file that has two different types of forms <form action=searchpath
I have a form that has a public property public bool cancelSearch = false;
I have a form that has a group of 3 text_fields. I need two

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.