Alyssa-Charlie Posted February 26, 2023 Share Posted February 26, 2023 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); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/315951-crud-create-form-output-php/ Share on other sites More sharing options...
Solution requinix Posted February 26, 2023 Solution Share Posted February 26, 2023 1. Don't use mysqli_multi_query because you're running the three queries by themselves individually already. 2. Don't create queries where you put $_POST values directly into the SQL. It's extremely unsafe. Use prepared statements instead. Quote Link to comment https://forums.phpfreaks.com/topic/315951-crud-create-form-output-php/#findComment-1606040 Share on other sites More sharing options...
Barand Posted February 26, 2023 Share Posted February 26, 2023 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. Quote Link to comment https://forums.phpfreaks.com/topic/315951-crud-create-form-output-php/#findComment-1606054 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.