I have a website that people can register on, giving them a unique ID (primary key, auto increment) (stored in the USERS table). When they log in, they can update a list of wishes (stored in the WISHES table)
Now here is my problem:
the storing-in-the-database section of my wishes.php document looks like this:
require('db_connect.php'); // database connect script.
session_start();
if (isset($_POST['submit'])) { // if form has been submitted
$query = "INSERT INTO wishes(
w_id,
w_username,
w_wish1,
w_wish2,
w_wish3,
w_wish4,
w_wish5,
w_wish6,
VALUES (
'".$_POST['id']."',
'".$_POST['username']."',
'".$_POST['w1']."',
'".$_POST['w2']."',
'".$_POST['w3']."',
'".$_POST['w4']."',
'".$_POST['w5']."',
'".$_POST['w6']."')";
mysql_query($query) or die(mysql_error());
and my storing-in-the-database section of my register.php looks like this:
require('db_connect.php'); // database connect script.
$insert = "INSERT INTO users (
first_name,
last_name,
username,
password,
regdate,
email,
city,
state,
zip_code,
country,
sex,
hear_about_us,
last_login)
VALUES (
'".$_POST['first_name']."',
'".$_POST['last_name']."',
'".$_POST['uname']."',
'".$_POST['passwd']."',
'$regdate',
'".$_POST['email']."',
'".$_POST['city']."',
'".$_POST['state']."',
'".$_POST['zip_code']."',
'".$_POST['country']."',
'".$_POST['sex']."',
'".$_POST['hear_about_us']."',
'Never')";
$add_member = $db_object->query($insert);
if (DB::isError($add_member)) {
die($add_member->getMessage());
}
$db_object->disconnect();
how come when I add the users ID in the WISHES table, it doesnt add it? Is there a way I can tell the database that it is a foreign key, because it is a primary key in the USERS table.