I am building a table ('at_document') that has a foreign key (inherited from table 'client_profile') called 'client_id' which is an integer.
However, although the building of the tables (and the database as a whole) has not been a problem, I'm having difficulty writing the appropriate PHP code needed to populate the table 'at_document' with the 'client_id' foreign key reference, thus giving it referential integrity.
Does anybody know the script that I need here? Is it PHP code that is required or is it just an SQL insert (or other) instruction that I need (I am using MySQL).
I am pretty new to PHP (6 months, self taught), so am prone to making some simple errors....I was under the impression that the foreign key row would automatically populate (perhaps through inheritance??), once the user had run the relevant 'submit' conditional.
The goal for this part of the application that I am putting together is to store user supplied files/documents on our server. I want the submitted files to be accompanied by a 'client_id', in order for administrators to be able to see which files/docs refer to which users. Similarly, I also want the 'client_id' column in the 'at_document' table to be populated with the appropriate 'client_id' integer.
I have used the following lines of PHP code to run the SQL query in the script:
$query = "INSERT INTO at_document (file_name, file_size, file_type, description, upload_date) VALUES ('{$_FILES['upload']['name']}', {$_FILES['upload']['size']}, '{$_FILES['upload']['type']}', '$d', NOW())";
$result = @mysql_query ($query);
I have ommitted from the above insert command, the primary key 'upload_id' (auto increment, integer), and the foreign key, 'client_id' (integer).
I hope that this makes sense!!
Any help would be appreciated
Thanks
Will