theo Posted August 8, 2011 Share Posted August 8, 2011 having trouble with my second table: first table insert user record --> works fine/record added to table second table insert the user record to another table --> problem starts here..it seems the primary key keeps on incrementing but it does not show in the table: you can check the site at CODE: $q = "INSERT INTO masterpx (mpx_lname, mpx_fname, mpx_mname, mpx_bday, mpx_age, mpx_occupation, mpx_contact, mpx_address, mpx_spouse, mpx_father, mpx_mother, mpx_religion, mpx_nationality, mpx_citizenship, mpx_gender, mpx_cstatus, mpx_date_added) VALUES ('$ln', '$fn', '$mn', '$bday', '$age', '$oc', '$co', '$ad', '$sp', '$fa', '$mo', '$re', '$na', '$ci', '$ge', '$cs', NOW())"; // run the query: $r = @mysqli_query($dbc, $q); if (mysqli_affected_rows($dbc) == 1) { // insert to inpatient table: $q = "INSERT INTO inpx_admission (inpx_admission_date, mpx_idfk, doc_idfk) VALUES (NOW(), '$px_id', '$doc_id')"; $r = @mysqli_query($dbc, $q); Link to comment Share on other sites More sharing options...
Stuart Posted August 8, 2011 Share Posted August 8, 2011 Hi Theo, I think we're going to need a little more information to get a solution - I'm not even entirely sure what's problem we're trying to fix. Explain what you're trying to achieve (desired outcome) and what's actually happening at the moment (current outcome). If you're saying the result of that inserted rows check is FALSE then add: echo mysqli_error($dbc); in the else clause. Also as per the forum rules provide your PHP and MySQL versions so you can get accurate and timely responses. Link to comment Share on other sites More sharing options...
theo Posted August 8, 2011 Author Share Posted August 8, 2011 php:5.2.9 mysql:5.0.51a hi, thanks for the interest. there is indeed an error found: --->Cannot add or update a child row: a foreign key constraint fails (`docverse`.`inpx_admission`, CONSTRAINT `inpx_admission_ibfk_1` FOREIGN KEY (`mpx_idfk`) REFERENCES `masterpx` (`mpx_id`)) im trying to create a patient record then automatically admits the patient in the other table.. flow of the program: 1. search if the patient is new or has an existing record -- 2. if new patient? add the patient(table:masterpatientrecord) then add to the second table(table:inpatient) 3. if patient exist in the masterpatient record? echo/print/update record then add to the second table.. current outcome: patient record works fine..can insert new records but not to the secord table; for existing patient records both can update record and insert to the second table..----> Link to comment Share on other sites More sharing options...
theo Posted August 8, 2011 Author Share Posted August 8, 2011 hi stuart thanx for the help..i was able to crack the problem.. Link to comment Share on other sites More sharing options...
Recommended Posts