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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:09:42+00:00 2026-06-04T19:09:42+00:00

I want to insert my data into a table depending on the value I

  • 0

I want to insert my data into a table depending on the value I select from the drop down.
Actually I have two tables, Categories and Products. Both are interlinked with CategoryID.
Now I have a form through this I am trying to add a product. I have a dropdown for categories. I will select a category from the dropdown and then I will add related products to that category.

After getting the form data, I fetched my table for CategoryID like this:

 include('includes/conn.php');
 if (isset($_POST['submit']))
 { 
     $CategoryName = $_POST['cat'];
     echo $CategoryName; 
     $ProductName = mysql_real_escape_string(htmlspecialchars($_POST['ProductName']));
     $ProductCode = $_POST['ProductCode'];
     $Specification = $_POST['Specification'];
     $Description = $_POST['Description'];
     $CostPrice = $_POST['CostPrice'];
     $DisplayPrice = $_POST['DisplayPrice'];
     $ProductID = $_POST['ProductID'];
     $Productimage = $_POST['ProductImage'];
     $sql = "select * Categories";
     $result = mysql_query ($sql);
     $row = mysql_fetch_array($result);
     $Category_ID = $row['CategoryID'];

after this I am not getting how to do. Except that condition my code inserts the record successfully.
my complete code withouth selecting the categoryid like this

<?php 
}

include('includes/conn.php');
    if (isset($_POST['submit']))
    { 
        $ProductName = mysql_real_escape_string(htmlspecialchars($_POST['ProductName']));
        $ProductCode = $_POST['ProductCode'];
        $Specification = $_POST['Specification'];
        $Description = $_POST['Description'];
        $CostPrice = $_POST['CostPrice'];
        $DisplayPrice = $_POST['DisplayPrice'];
        $ProductID = $_POST['ProductID'];
        $Productimage = $_POST['ProductImage'];
        if ($ProductName == '' || $ProductCode == ''|| $Specification == '' || $Description == '' || $CostPrice == '' || $DisplayPrice =='')
        {
            echo  "Please fill in all required fields";
            renderForm($ProductID, $ProductName, $ProductCode, $Description, $Specification, $CostPrice, $DisplayPrice,  $error);
        }
        else
        {
            $sql = "INSERT into Products SET ProductName='$ProductName', ProductCode='$ProductCode', Specification ='$Specification', Description = '$Description', CostPrice = $CostPrice, DisplayPrice = $DisplayPrice, ProductImage = '$ProductImage'";
            mysql_query($sql) or die(mysql_error());
            echo " Successfully Added "; 
            //header("Location: view.php"); 
        }
    }
    else
    {
        renderForm('','','','','','','','','');
    }
   ?> 

Please suggest how to do it?

  • 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-04T19:09:44+00:00Added an answer on June 4, 2026 at 7:09 pm
    $sql = "INSERT INTO Products (ProductName, ProductCode, ...) VALUES ('".$ProductName."', '". $ProductCode ."', ...";
    

    This is how you use an insert query.

    http://www.tizag.com/mysqlTutorial/mysqlinsert.php

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

Sidebar

Related Questions

I have a user table. I want to insert data into my user table.
I want to insert data into a table where I don't know the next
I want to insert data to database. I have a table, named member that
I want to insert some data into a table (id PK autoincrement, val) with
I am trying to insert data from one of my existing table into another
I have a situation similar to the following question: Insert Data Into SQL Table
i have a XML File i want to insert data from that XML file
I want to insert data into sql table in silverlight application. I know how
I want to insert data into a table, then if the table already has
I want to insert some data into a table associated with dates for the

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.