Jump to content
Sign in to follow this  
jeliey

tak leh insert value dlm database (PHP MySQL)

Recommended Posts

satu lg sy perasan, kl awk tgk struktur db awk, care penggunaan foreign key tu salah. ni sql dump yg awk bg:
Code:

--
-- Constraints for table `issues`
--
ALTER TABLE `issues`
  ADD CONSTRAINT `issues_ibfk_1` FOREIGN KEY (`id`) REFERENCES `category` (`catid`) ON DELETE CASCADE;

kl ikut sql dump yg awk bg tu, foreign key dlm table issues ialah id (yg mne dh disetkan sebagai primary key dan nilainye auto increment). foreign key ni akan merujuk kepada field catid dalam table category. ini bermaksud nilai field id dlm table tu mst ade dlm catid kat table category. sepatutnye, field catid dlm table issues tu awk kne buat sebagai foreign key yg merujuk kpd field catid dlm table category.
so, drop blk table issues dan bina blk table tu pkai sql ni:
Code:

-- phpMyAdmin SQL Dump
-- version 3.1.3.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Dec 04, 2009 at 11:27 PM
-- Server version: 5.1.33
-- PHP Version: 5.2.9

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `test`
--

-- --------------------------------------------------------

--
-- Table structure for table `issues`
--

CREATE TABLE IF NOT EXISTS `issues` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  `catid` int(11) NOT NULL,
  `idesc` varchar(255) NOT NULL,
  `pid` int(11) NOT NULL,
  `idate` date NOT NULL,
  `userid` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `catid` (`catid`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

--
-- Dumping data for table `issues`
--

INSERT INTO `issues` (`id`, `title`, `catid`, `idesc`, `pid`, `idate`, `userid`) VALUES
(2, 'Foreign Key', 1, 'How to create foreign key in MySQL database?', 3, '2009-11-17', 1),
(3, 'Online Shopping System', 1, 'Is it possible to drag the items into cart? it means that, users don''t have to click', 2, '2009-11-24', 1);

--
-- Constraints for dumped tables
--

--
-- Constraints for table `issues`
--
ALTER TABLE `issues`
  ADD CONSTRAINT `issues_ibfk_1` FOREIGN KEY (`catid`) REFERENCES `category` (`catid`);

rasenye xkn kuar error dh kl awk fix kedua-dua bnde yg sy gtau dlm dua2 reply sy nih. kl dh xde error, ade bnde lg akan sy bgtau kemudian ::icon_biggrin::

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...