Jump to content

CRUD create form, output PHP


Alyssa-Charlie
Go to solution Solved by requinix,

Recommended Posts

I am making a CRUD. I get stuck at the output of the create. When creating, I have to save the data in the output, which is entered in the html form, in 3 different tables. As I have the code now, the data is only stored in the table lid and not in email and telefoonnummer. the primary key in the 3 tables is Lidnummer.

<?php

require_once 'login.php';

$conn = new mysqli ($hn, $un, $pw, $db);

if ($conn->connect_error) {

die("Connection failed: " . $conn->connect_error);

}

if(isset($_POST['submit']))

{

$Naam = $_POST['Naam'];

$Voornaam = $_POST['Voornaam'];

$Huisnummer = $_POST['Huisnummer'];

$Postcode = $_POST['Postcode'];

$Telefoonnummer = $_POST['Telefoonnummer'];

$Emailadres = $_POST['Emailadres'];

$query = "INSERT INTO lid (Naam, Voornaam, Postcode, Huisnummer) VALUES ('$Naam', '$Voornaam','$Postcode','$Huisnummer')";

$query1 = "INSERT INTO email(Emailadres) VALUES ('$Emailadres')";

$query2 = "INSERT INTO telefoonnummers(Telefoonnummer) VALUES ('$Telefoonnummer')";

mysqli_query($conn, $query);

mysqli_query($conn, $query1);

mysqli_query($conn, $query2);

$result = mysqli_multi_query($conn, $query);

if($result)

{

echo "Data Inserted Successfully!";

}

else {

echo "Data Not Inserted!. Error: " . $query . "" . mysqli_error($conn);

}

}

?>

Link to comment
Share on other sites

Having read you next post where you say that lids can have multiple emails or phonenumbers, how is that going to work if ...

9 hours ago, Alyssa-Charlie said:

the primary key in the 3 tables is Lidnummer.

Primary keys have to be unique which will allow only one of each per lidnummer.

You need to rethink your data model.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.