One suggestion. When you are inserting a record to the table, you don't have to insert 'NULL' if its an auto increment field. Mysql will do it for you.
Ie.,
$orange_insert = "INSERT INTO orange (orange_name, orange_add)
VALUES ('$val_name', '$val_add')";
Secondly, the 'error' you are getting is not exactly an error, but a notice. You get these notices if you use a variable without initializing it. You can turn off the notices by changing your php.ini file. Change error reporting in php.ini to the following if you want to disable notices.
Quote ...
error_reporting = E_ALL & ~E_NOTICE
This means, show all errors except notices.
If you don't want to disable notices, then start initializing all your variables before using it.
Finally, You have an error in your code.
However nav33n, I have got this problem struck for days and not able to solve it. Not sure if you can help as well. Basically I have 2 tables (A and B) each has their own ids and fields. somehow i would like to join up A and B. I understand that's a 'select - join' function to use for this case. But what Im trying to do is having the user to enter values into Table B where the id of Table B will automatically appear onto Table A. There will be no duplication on Table B.
For this case, am i suppose to set up the relationship at the begining when i created the table? If so what is the code for it?
Sorry to touble u again.
But what Im trying to do is having the user to enter values into Table B where the id of Table B will automatically appear onto Table A.
If I get it right, When you insert a record to table B, you can get the id by using mysql's last_insert_id or php's mysql_insert_id. You can then insert a record in table A using this value.
You can make id column of both the tables A and B as primary key (since no duplicates are allowed). Then, you can have a column in table A (for example, tableB_id) and make it a foreign key referencing table B's id column. You can add constraints after creating a table. Thats not a problem! http://dev.mysql.com/doc/refman/5.1/...nstraints.html
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.