I don't know why this isn't working.
MYSQL TABLES:
Code:
CREATE TABLE users(
user_id BIGINT(10) NOT NULL AUTO_INCREMENT,
password VARCHAR(20) NOT NULL,
date date NOT NULL,
email VARCHAR(80) NOT NULL,
PRIMARY KEY(user_id)
);
CREATE TABLE advert(
user_id BIGINT(10) NOT NULL,
ad_id BIGINT(10) NOT NULL AUTO_INCREMENT,
email VARCHAR(80) NOT NULL,
expiry_date DATE NOT NULL,
item_desc VARCHAR(200) NOT NULL,
PRIMARY KEY(ad_id),
FOREIGN KEY(user_id) references users(user_id) NOT NULL ON UPDATE CASCADE ON DELETE CASCADE
);
PHP CODE:
Code:
$lol="SELECT users.user_id
FROM users
INNER JOIN advert
ON users.user_id = advert.user_id";
$sql="INSERT INTO advert (user_id, email,expiry_date, item_desc) VALUES('$lol','$_POST[email]','$_POST[expiry]','$_POST[itemdesc]')";
The only way I've got this to function without it saying 'cannot update/add child row'is if i manually enter the user_id in the values, but obviously that's useless. The tables seem to be linked okay because if i try entering a user_id into the adverts table that doesn't correspond to a user_id in the users table it throws the same 'cannot update child row' error.
Could anybody tell me where I'm going wrong?
Thanks in advance. Rob.
