I have a problem inserting a data into another table that has foreign key using PHP. I have a table named CUSTOMER_INFORMATION with fields(customer_no(PK), first_name, last_name, etc..) and a CATERING_RESERVATION table with fields(catering_no(PK), type_of_event, number_of_persons, customer_no(FK), etc).. I wanted to insert the customer_no in the CATERING_RESERVATION table but I have this error:
"Cannot add or update a child row: a foreign key constraint fails (`thesis/catering_reservation`, CONSTRAINT `catering_reservation_ibfk_1` FOREIGN KEY (`customer_no`) REFERENCES `customer_information` (`customer_no`) ON DELETE CASCADE)"
But I think I lack some codes on this. I'm just a newbie in php.[code]...
Insert Query Doesn't Insert Data To Mysql Database Table?
i have a recipe table and ingredient table the primary key of both tables are auto increament and primary key of recipe is foreign key in ingredient. i post data from html to php.Note that my ingredient textboxes are generated dynamically and successfully post the data to php script. posted data is correct when i insert this data to table my query working fine but data is not added to mysql table. my code and output is
$sql = "insert into recipe (rec_id, Name, Overview,category, Time, Image) values ('', '$name','$overview','$category','$time','$TARGET_PATH')"; $result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error()); $rec_id = mysql_insert_id();
Grab Data From A Table, Echo, Then Insert It Into A New Table...
I'm trying to do is count the number of times usernames shows up in a table. I then want to reinsert that information into a different table with the Username in column1 & the occurrences in column2 for every user that is echoed on the page. Code:
Checkbox Form - Insert Row Data From One SQL Table To Another Table?
I have two tables "tbl_jobs" and "tbl_jobs_done". I have an SQL query which displays and formats my daily job list from tbl_jobs SQL database, and has a checkbox at the end of each row. I want to be able to select 1, 2, 3 or more checkboxs and then click my submit button which will then insert the data into my second MySQL database named "tbl_jobs_done". i have spent hours and hours looking at tutorials and other peoples forum posts but can't seem to find something that hits home and works for me I only need the jobs_id field data from the tbl_jobs to be inserted into tbl_jobs_done table and into jobs_id field. I have other data on the form that will also be submitted. But in general, that's all I need. Here is my SQL Query ->
CakePHP - Custom HasOne Object Association - Using A Join Table Instead Of In-table Foreign Keys?
In CakePHP, I'm trying to build a $hasOne relationship, but I can't add a foreign key to the tables (for legacy reasons). Is there any way I can create a join table (object1_object2) and link them together like this? I want to leverage Cake's powerful object relationship functionality, so if there's a way I can make this custom association permanent throughout the model, without always building a custom $options array for each find(), that'd be great. (Maybe a bindModel in the Model's initalize()?)
Use Multiple Foreign Keys In One Table Referencing Another Table In Cakephp?
Using cakephp, I have a generic address table, which I want to link to customers, vendors, contacts. most of the tables only have a 1 to 1 relationship, but I want my customers table to have 2
perhaps for clarification: I have a customers table
id, int mailing_address_id, int billing_address_id, int
and an addresses table
id,int addr, varchar city, varchar etc....
Now I know I could put a customer_id in the addresses table. But I don't want to do that because I have a vendors table, and contacts table, and other tables that all are going to use the addresses table. the customer_id would not really be relavant to those other tables.
I'd like the Customer model to automatically link in the two addresses
Put The Value Of One Field In The First INSERT Into The Second As A Foreign Key
I am developing what could be likened to a very simple php/mysql forum solution for a client. I have come to an instance where I need to do two INSERT queries on my MySQL database to put data into two tables. However i need to put the value of one field in the first INSERT into the second as a foreign key sorta thing.
The field i need the value for is an auto incrementing field. Is it possible to return the value of the auto incremented field after and INSERT query so that i can then use this value and insert it into the second table. I think I could probably do this by doing a SELECT query in between to find the max value of that column and then use that but I can't see this being the most efficient method.
i am trying to use a session to insert in to the database a user_id of a user who is posting a topic in to the topic table to act as a foreign key in the topic table. but i kept getting 0 in the user_id column instead of the real userid below is my code.
<?php require_once('Connections/forum_con.php'); ?> <?php //initialize the session session_start(); require_once('Connections/con_user.php');
CREATE TABLE folders( id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, parent INT(11) UNSIGNED NOT NULL, PRIMARY KEY (id), INDEX FK_folders_folders_id (parent), CONSTRAINT FK_folders_folders_id FOREIGN KEY (parent) REFERENCES folders (id) ON DELETE CASCADE ON UPDATE CASCADE )
1 folder can have many subfolders and can belongs to one another folder. If it's root folder then parent will contain it's own ID. The problem is: how can I create root folder? ID is auto_increment and I can get it only after inserting a row but I cant insert row while parent is not defined. Recursion...
I am getting the error msg; Mysql error, data not saved, try again -You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 7
PHP Code: <?php // PUT YOUR DATABASE CONNECTION SCRIPT HERE $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="merchandising"; // Database name
i have a user(members) form that pulls from my database 3 fields: name, age, about. i want the user to be able to edit their info then re-submit back to the database. however, i want to have some control as to what they edit their info to. so instead of just update the info back to the database.
i want to hve any fileds that have 'changed' by the user get put to a different table(review), so after i have approved the changes i will 'update the master user table. is there a logical way that i could do this, i guess just flag any fields that have changed when the user form is submitted.
I am trying to find the fastest way to insert data into a table (data from a select) I always clear the table:
TRUNCATE TABLE table;
Then I do this to insert the data:
INSERT INTO table(id,total) (SELECT id, COUNT(id) AS Total FROM table2 GROUP BY id);
Someone told me I shouldn't do this. He said this would be much faster: CREATE TABLE IF NOT EXISTS table (PRIMARY KEY (inskey)) SELECT id, count(id) AS total FROM table2 GROUP BY id I think my solution is cleaner, because I don't have to check for the table.