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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:49:26+00:00 2026-06-12T21:49:26+00:00

I have 3 tables which is subcategory, product, and prod_category. When I create my

  • 0

I have 3 tables which is subcategory, product, and prod_category.

When I create my product, if it successful, it will return the successfull product_id, after that it will capture the form subcategory column ,to carry out the next query which insert product_id and subcategory_id to the prod_category table. I tested out in a single php file to test the whether the function is working. It can insert, but when I fit into my situation, it was giving me this error.

Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (yokotachi.prod_category, CONSTRAINT prod_category_ibfk_4 FOREIGN KEY (product_id) REFERENCES product (product_id) ON DELETE CASCADE ON UPDATE CASCADE) in C:\xampp\htdocs\yokotachi\models\Prod_category.php on line 27

I confirm that, 2 parameter was passed into the function, but i dont know why it cannot perform the query.

if($_POST){ 
$title = mysql_real_escape_string($_POST['title']);
$model = mysql_real_escape_string($_POST['model']);
$description = stripslashes($_POST['description']);
$feature = stripslashes($_POST['feature']);
$specification = stripslashes($_POST['specification']); 

$subcategory_name = mysql_real_escape_string($_POST['product_subcategory']);

$sub_obj = $subcategory->find_by_sub_category_name($subcategory_name);

$subcategory_id = $sub_obj->sub_category_id;
echo $subcategory_id;
$executed_product_id=
    $product->create($title,$model,$description,$feature,$specification);
echo "im here".$subcategory_id;
echo $executed_product_id;
$responde = $prod_category->create($executed_product_id,$subcategory_id);
if($responde){
    echo "<script>";
    echo "alert(".$executed_product_id.");";
    echo "</script>";
    header("location: ../../../views/admin/product/product_index.php");
}}

i did saw 1 post is reindex problem, and asked to truncate the table. But I have no idea , how to perform the truncate query in my situation.

Thanks in advance.

  • 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-12T21:49:27+00:00Added an answer on June 12, 2026 at 9:49 pm

    The error message seems to be telling you that the product ID number you’re trying to use in the table “prod_category” doesn’t exist in the table “product”.

    You need to find out what value $executed_product_id has after this line executes.

    $executed_product_id=
        $product->create($title,$model,$description,$feature,$specification);
    

    If the value it has isn’t in the table “product”, then that’s your problem. The foreign key reference requires that product ID to exist in “product” before you can use it in “prod_category”.

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

Sidebar

Related Questions

I have two tables which have some transactional stuff stored in them. There will
newbie programmer here. I have 3 tables namely product, category, and subcategory. I configured
I have 3 tables which need to be linked in an SQL statement (I'm
I have 2 tables which I want to query from. The first table (lets
I have two tables which looks something like this Table Queue int ID; string
I have two tables which are used to store details of different types of
I have two tables which I want to join together using a left outer
I have three tables which are defined as: class User(Base): __tablename__ = 'users' id
I use Hibernate with Java. I have two tables which are associated with foreign
I have some tables for which I have no reason to ever update from

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.