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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:36:31+00:00 2026-06-11T14:36:31+00:00

I got three tables, a parent one (called profiles ) and two tables one

  • 0

I got three tables, a parent one (called profiles) and two tables one can consider a child (values and url). This is just a test to play around so don’t mind missing SQL injection security.

CREATE TABLE `profiles` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `profile` int(10) unsigned NOT NULL,
 `url_hash` varchar(32) NOT NULL,
 PRIMARY KEY (`id`,`profile`,`url_hash`),
 UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=latin1


CREATE TABLE `urls` (
 `id` int(10) unsigned NOT NULL,
 `url` text NOT NULL,
 `title` text,
 PRIMARY KEY (`id`),
 CONSTRAINT `urls_ibfk_1` FOREIGN KEY (`id`) REFERENCES `profiles` (`id`) 
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1


CREATE TABLE `values` (
 `id` int(10) unsigned NOT NULL,
 `seller` text NOT NULL,
 `seller_language` text,
 `quality` tinyint(3) unsigned NOT NULL,
 `note` text,
 `price` int(10) unsigned NOT NULL,
 `count` tinyint(3) unsigned NOT NULL,
 PRIMARY KEY (`id`),
 CONSTRAINT `values_mtg_ibfk_1` FOREIGN KEY (`id`) REFERENCES `profiles` (`id`) 
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1

I’m executing the following three queries as transaction (surrounding autocommit(false), commit() & rollback() omitted):

$db->query('INSERT INTO profiles(id, profile, url_hash) 
VALUES (null, ' . $profile . ', "' . md5($url) . '")')
or throwException(...);

$db->query('INSERT INTO urls(id, url, title) 
VALUES (' . mysqli_insert_id($db) . ', "' . $url . '", "' . $c->data('title') . '")')
 or throwException(...);

$db->query('INSERT INTO values(id, seller, seller_language, quality, 
note, price, count) 
VALUES (' . mysqli_insert_id($db) . ', "'. $seller .'", "'. $seller_lang .'", 
'. $qual .', "'. $notice .'", '. $price .', '. $ount .')') 
or throwException(..);

Resulting in

exception 'Exception' with message 'Query failed (table: values): 
(1452) Cannot add or update a child row: a foreign key constraint fails
(`crawler`.`values`, CONSTRAINT `values_ibfk_1` FOREIGN KEY (`id`) REFERENCES
`profiles` (`id`) ON DELETE CASCADE ON UPDATE CASCADE)'

and I just don’t get why. It is stating the corresponding id in the parent table is missing. If that’s the case why does the second query work since its table urls got the very same foreign key relationship to table profiles like table values?

Edit: there is a huge flaw in my database design, regarding the FK in values which can’t be unique. Gonna think about it tomorrow. 🙂

  • 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-11T14:36:32+00:00Added an answer on June 11, 2026 at 2:36 pm

    The error resulted from my flawed database design (what I never thought of).
    In values id was unique while my script tried to INSERT multiple values with the same id.

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

Sidebar

Related Questions

Say I've got two tables: Parent id | name Child id | parentId |
I have a problem where I have this three grandfather parent and child and
I'm SO close, but so far. I've got two tables, one for publication details,
I've got my database set up with three tables - code, tags, and code_tags
I've got three boolean values A, B and C. I need to write an
I have two classes. One is called Employee and the other EmployeeDetails that has
I have got a problem with two tables: CREATE TABLE IF NOT EXISTS `addresses`
Uppon trying to delete a record in one of my tables I got the
I've got three tables in a MySql database that I'm joining in a query
Say I have two classes: Parent and Child . A Parent has a property

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.