Hi,
Relatively new to the PHP/MySQL world, hoping you can help. I have built a database and I am having trouble grasping one little part. I need to get the id that is a primary key, auto increment, in one table (document) and put it into another table(key_doc_join) as the data is being entered.
Here is the plan. I have inserted $title, and $newid into table document. Now I need $newid to also go into the docid column of the key_doc_join table. The key_doc_join table is a little scary to populate, I have half of it working. As info is put into the database, a bunch of stuff goes into table 'document' and some of the stuff goes into a keyword table, which breaks down phrases and looks for repeating words before they are allowed into the table.
So now the goal of my code is to say if the $keyword isn't in the keyword table, add it, then place the keyword's id into the keydocjoin table, along with the documents id that was put into the document table. I have the keyword's id going into to the keydocjoin table, but the code trips up when it goes to get the docid, which is the $newid.
Hmmmmm did any of that make sense????
So I suspect that my code is having trouble where I assign the variable $newid:
because when I print the $newid, only the default is printed (0), not the actual id. If I get this $newid variable to work, I should be able to figure out the rest from there.
Here is my code, that's in the middle of a mountain of other code, that should put the keyword's id and the document's id into the key_doc_join table:
so sorry if I have entirely confused you, but I appreciate any guidance that you can offer.
Thank you!
Michelle
Relatively new to the PHP/MySQL world, hoping you can help. I have built a database and I am having trouble grasping one little part. I need to get the id that is a primary key, auto increment, in one table (document) and put it into another table(key_doc_join) as the data is being entered.
Here is the plan. I have inserted $title, and $newid into table document. Now I need $newid to also go into the docid column of the key_doc_join table. The key_doc_join table is a little scary to populate, I have half of it working. As info is put into the database, a bunch of stuff goes into table 'document' and some of the stuff goes into a keyword table, which breaks down phrases and looks for repeating words before they are allowed into the table.
So now the goal of my code is to say if the $keyword isn't in the keyword table, add it, then place the keyword's id into the keydocjoin table, along with the documents id that was put into the document table. I have the keyword's id going into to the keydocjoin table, but the code trips up when it goes to get the docid, which is the $newid.
Hmmmmm did any of that make sense????
So I suspect that my code is having trouble where I assign the variable $newid:
Code:
$SQL = "INSERT INTO document (docid, title) VALUES ('$newid', '$title')";
mysql_query($SQL);
$newid= mysql_insert_id();
printf ("<br>here is the newid $newid");
because when I print the $newid, only the default is printed (0), not the actual id. If I get this $newid variable to work, I should be able to figure out the rest from there.
Here is my code, that's in the middle of a mountain of other code, that should put the keyword's id and the document's id into the key_doc_join table:
Code:
$keyID = mysql_query("SELECT keyid FROM keywords WHERE keytype=$eachword[$k]");
$ID = mysql_result($keyID, "0", "keyid");
$inputlink = "INSERT INTO key_doc_join(keyid,docid) VALUES($ID,$newid)";
mysql_query($inputlink);
so sorry if I have entirely confused you, but I appreciate any guidance that you can offer.
Thank you!
Michelle