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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:29:00+00:00 2026-06-04T23:29:00+00:00

I’ve been reading some questions with the same problem I have but have not

  • 0

I’ve been reading some questions with the same problem I have but have not found the solution

Database Estructure

CREATE TABLE material (
  cve_mat varchar(12),
  type_mat varchar(20),
  author_mat varchar(40),
  status varchar(2),
  primary key(cve_mat)   
) ENGINE = INNODB;

CREATE TABLE users (
  cve_user varchar(8),
  name_user varchar(25),
  lastn_user varchar(25),
  email_user varchar(25),
  primary key(cve_user)
)ENGINE = INNODB;

CREATE TABLE material_user (
  cve_mat varchar(8),
  cve_user varchar(8),
  start_mat date,
  end_mat date,
  foreign key(cve_mat) references material(cve_mat)
    ON UPDATE CASCADE
    ON DELETE CASCADE,
  foreign key(cve_user) references users(cve_user)
    ON UPDATE CASCADE
    ON DELETE CASCADE
) ENGINE = INNODB;

And when execute these instructions:

......
$query = "INSERT INTO material_user VALUES ('$cvemat','$ncontrol',NOW(),DATE_ADD(current_date, interval '$days' day))";
$result = mysql_query($query) or die(mysql_error());

if ($result) {
$query = "UPDATE material SET status = 'YES' WHERE material.cve_mat = '$cvemat'";
$result = mysql_query($query) or die(mysql_error());

if ($result){
    return true;
} else {
    return false;
}
} else {
return false;
}

And display this error:

Cannot add or update a child row: a foreign key constraint fails (`biblioteca/material_prestamo`, CONSTRAINT `material_prestamo_ibfk_1` FOREIGN KEY (`cve_mat`) REFERENCES `material` (`cve_mat`) ON DELETE CASCADE ON UPDATE CASCADE)

I would greatly appreciate your help!

  • 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-04T23:29:02+00:00Added an answer on June 4, 2026 at 11:29 pm

    First, the column types for the foreign key should match the referencing tables:

    material_user

    cve_mat varchar(8),
    

    material

    cve_mat varchar(12),
    

    Those two column types should be equal.

    Before your insert statement you can perform some debugging:

    SELECT * FROM material WHERE cve_mat='$cvemat'
    

    If all seems okay, you can run this to find out more details:

    SHOW INNODB STATUS;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I have a reasonable size flat file database of text documents mostly saved in
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has

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.