Hey all,
I'm very new to PHP and MySQL and this is my first script I am scripting. Thus far, I have created a registration database with MySQL where people input usernames, passwords, and address, etc. that I have been successful with. Now, when they are logged in, I have them update a list of wishes, that I would like to save in the database.
My first table in MySQL, titled "users" contains their id (a primary key that automatically increments), username, password, address, etc.
Now, I would like to create another table titled "wishes" that corresponds with each persons "id" (found in the 'users' table). I also labeled "id" a primary key in the "wishes" table as well...is this wrong? Should it be a so-called 'foreign key'? Anyways, here is my code for inputting users wishes into my database, and when they submit, there are two things that go wrong:
1) It adds all the wishes, except it doesnt add the right id, the id it adds for anybody is "0" when in reality they are, for example, "15".
2) If they want to modify their wishes, it wont let them because there is already something in the database for their wishes. Is there any way to make it so if they modify a wish, it will erase the old and add the new?
Thanks a lot guys in advance, and here is a copy of the code I'm using:
<?php
require('db_connect.php'); // database connect script.
if (isset($_POST['submit'])) { // if form has been submitted, you can add them to db
$query = "INSERT INTO wishes(
id,
wish1,
wish2,
wish3,
wish4,
wish5,
wish6)
VALUES (
'".$_POST['$_SESSION[id]']."',
'".$_POST['w1']."',
'".$_POST['w2']."',
'".$_POST['w3']."',
'".$_POST['w4']."',
'".$_POST['w5']."',
'".$_POST['w6']."')
mysql_query($query) or die(mysql_error());
?>