I’m making an attempt so as to add a international key to a submit kind. I made a submit kind that provides knowledge to the database, however am uncertain how one can add the international key. I made the var $Address_ID, which is the closest I’ve gotten to date.
Right here is the front-end kind:
<kind technique="put up">
<!-- CENTRAL_ADDRESS -->
<label for="Add1">Add1: </label><br>
<enter kind="textual content" id="Add1" identify="Add1"><br>
<label for="Add2">Add2: </label><br>
<enter kind="textual content" id="Add2" identify="Add2"><br><br>
<label for="Metropolis">Metropolis:</label><br>
<enter kind="textual content" id="Metropolis" identify="Metropolis"><br><br>
<label for="State">State:</label><br>
<enter kind="textual content" id="State" identify="State"><br><br>
<label for="Zip">Zip</label><br>
<enter kind="textual content" id="Zip" identify="Zip"><br><br>
<label for="Telephone">House Telephone:</label><br>
<enter kind="textual content" id="Telephone" identify="Telephone"><br><br>
<label for="E-mail">E-mail Handle:</label><br>
<enter kind="textual content" id="E-mail" identify="E-mail"><br><br>
<!-- CENTRAL_STUDENT -->
<label for="First_Name">First Identify: </label><br>
<enter kind="textual content" id="First_Name" identify="First_Name"><br>
<label for="Last_Name">Final Identify: </label><br>
<enter kind="textual content" id="LAst_Name" identify="Last_Name"><br>
<label for="Middle_Name">Center Identify: </label><br>
<enter kind="textual content" id="Middle_Name" identify="Middle_Name"><br>
<enter kind="submit" identify="nameBtn" worth="submit">
</kind>
</kind>
Right here is the backend kind:
if(isset($_POST['nameBtn']))
{
world $wpdb;
// CENTRAL_ADDRESS
$Add1 = sanitize_text_field($_POST['Add1']);
$Add2 = sanitize_text_field($_POST['Add2']);
$Metropolis = sanitize_text_field($_POST['City']);
$State = sanitize_text_field($_POST['State']);
$Zip = sanitize_text_field($_POST['Zip']);
$Telephone = sanitize_text_field($_POST['Phone']);
$E-mail = sanitize_text_field($_POST['Email']);
// CENTRAL_STUDENT
$First_Name = sanitize_text_field($_POST['First_Name']);
$Last_Name = sanitize_text_field($_POST['Last_Name']);
$Middle_Name = sanitize_text_field($_POST['Middle_Name']);
//Overseas Key displayed beneath Central_Student. Factors to ID key within the Central_Address desk
$Address_ID = $wpdb->question("FOREIGN KEY (Address_ID) REFERENCES" .'Central_Address'. " (ID)");
// Central_Student Desk
$wpdb->insert('Central_Student', array('First_Name'=>$First_Name, 'Last_Name'=>$Last_Name, 'Middle_Name'=>$Middle_Name, $Address_ID));
//Central_Address Desk
$wpdb->insert('Central_Address', array('Add1'=>$Add1, 'Add2'=>$Add2, 'Metropolis'=>$Metropolis, 'State'=>$State, 'Zip'=>$Zip, 'E-mail'=>$E-mail, 'Telephone'=>$Telephone));
}
There are two tables during which I’m making an attempt so as to add knowledge: Central_Student, and Central_Address.
Central_Address fields: ID(PK and hidden), Add1, Add2, Metropolis, State, Zip, E-mail and Telephone.
Central_Student fields: Address_ID(FOREIGN KEY), First_Name, Last_Name, and Middle_Name.
After the submit button, the ID from the Central_Address desk needs to be displayed as a international key as the sector Address_ID within the desk Central_Student. However I have no idea how one can implement this. Any strategies could be tremendously appreciated.