Jump to content
Larry Ullman's Book Forums

2 Table Insert Problem-Structure Or Syntax Error?


Recommended Posts

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 post
Share on other sites

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 post
Share on other sites

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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...