CREATE TABLE users( USERID BIGINT AUTO_INCREMENT, FNAME CHAR(50), LNAME CHAR(50), EMAIL CHAR (100), PHONE CHAR (50), PRIMARY KEY (USER_ID), UNIQUE KEY EMAIL (EMAIL), UNIQUE KEY PHONE (PHONE) ) ENGINE=InnoDB CHARSET=utf8mb4; CREATE TABLE items( ITEMS_ID BIGINT AUTO_INCREMENT, USERID BIGINT, ITEMS_TO BIGINT, ITEMS_FROM BIGINT, ACCEPTED_ITEMS BIGINT, PRIMARY KEY (ITEMS_ID), FOREIGN KEY (USERID) REFERENCES users(USERID), FOREIGN KEY (ITEMS_TO) REFERENCES users(USERID), FOREIGN KEY (ITEMS_FROM) REFERENCES users(USERID), FOREIGN KEY (ACCEPTED_ITEMS) REFERENCES users(USERID) )ENGINE=InnoDB CHARSET=utf8mb4; ERROR DBD::mysql::st execute failed: Cannot add or update a child row: a for +eign key constraint fails (`db701`.`items`, CONSTRAINT `items_ibfk_2` + FOREIGN KEY (`ITEMS_TO`) REFERENCES `users` (`USERID`)) $ID = '1'; $NULL = 'NULL'; $ID2 = '2'; $ID3 = '1'; my $update = $DBH->prepare("UPDATE items SET ITEMS_TO =?, ITEMS_FROM = +? WHERE USERID =? AND ITEMS_ID = ?"); $update->execute($ID, $NULL, $ID2, $ID3); $update->finish(); it works without ITEMS_FROM and i want to set ITEMS_FROM to null this works my $update = $DBH->prepare("UPDATE items SET ITEMS_TO =? WHERE USERID +=? AND ITEMS_ID = ?"); $update->execute($ID, $ID2, $ID3); $update->finish();

In reply to DBD::mysql::st execute failed by bigup401

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.