Jump to content

Search the Community

Showing results for tags 'foreign'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. Hi, I am attempting to insert a foreign key into a table along with other information, but I am getting an error message: Could not insert data into DataBase: Cannot add or update a child row: a foreign key constraint fails (`collectionsdb2`.`collections`, CONSTRAINT `collections_ibfk_1` FOREIGN KEY (`cat_id`) REFERENCES `categories` (`cat_id`)) The insert statement is as follows: $sql = "INSERT INTO collections (cat_id, ctitle, csubject, creference, cmaterial, ctechnic, cwidth, cheight, cperiod, cmarkings, cdescription, csource, cartist, cfilename) VALUES ($cat_id, '$ctitle', '$csubject', '$creference', '$cmaterial', '$ctechnic', '$cwidth', '$cheight', '$cperiod', '$cmarkings', '$cdescription', '$csource', '$cartist', '" . $image['name'] . "')"; $result = mysql_query($sql) or die ("Could not insert data into DataBase: " . mysql_error()); exit; And my two tables are as folows: /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; DROP TABLE IF EXISTS collectionsdb2.collections; CREATE TABLE `collections` ( `c_id` int(11) NOT NULL AUTO_INCREMENT, `cat_id` int(4) DEFAULT NULL, `ctitle` varchar(65) NOT NULL, `csubject` varchar(65) DEFAULT NULL, `creference` varchar(65) DEFAULT NULL, `cyear` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `cmaterial` varchar(65) DEFAULT NULL, `ctechnic` varchar(255) DEFAULT NULL, `cwidth` varchar(65) DEFAULT NULL, `cheight` varchar(65) DEFAULT NULL, `clength` varchar(65) DEFAULT NULL, `cdiameter` varchar(65) DEFAULT NULL, `cperiod` varchar(65) DEFAULT NULL, `cmarkings` varchar(255) DEFAULT NULL, `cdescription` text, `csource` varchar(65) DEFAULT NULL, `cartist` varchar(65) DEFAULT NULL, `cfilename` varchar(65) DEFAULT NULL, PRIMARY KEY (`c_id`), KEY `cat_id` (`cat_id`), CONSTRAINT `collections_ibfk_1` FOREIGN KEY (`cat_id`) REFERENCES `categories` (`cat_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; and /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; DROP TABLE IF EXISTS collectionsdb2.categories; CREATE TABLE `categories` ( `cat_id` int(4) NOT NULL AUTO_INCREMENT, `category` varchar(25) NOT NULL, PRIMARY KEY (`cat_id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; I am using a select option box to insert foreign key (category) into the table form the categories table. Please, how should I resolve this issue? Thanx. joseph
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.