I created two tables in sql. The first one is for the name addres etc, the second table is for other things. But I want to insert the values of the second table in the same id of the first table. Is that possible?
You want to access the last_insert_id(), how you access it depends on whether you are using mysqli or pdo.
Why are you wanting to have duplicate data? That goes against proper relational DB design.
If I use last insert ID, will it insert into the same id? I am using mysql.
Give us the high level overview of what you are doing instead of asking about your attempted solution to it.
session_start();
//initialize variables
$Pandadres = "";
$Huisnummer = "";
$Deel = "";
$Betaald = "";
$Nietbetaald = "";
$id = 0;
// connect to database
$db = mysqli_connect("xxxxx","xxxxx","xxxxx","xxxxx");
// if Opslaan button is clicked
if (isset($_POST["Opslaan"])){
$Pandadres = $_POST["Pandadres"];
$Huisnummer = $_POST["Huisnummer"];
$Deel = $_POST["Deel"];
$query = "INSERT INTO lokatie (id, Pandadres, Huisnummer, Deel, Betaald, Nietbetaald) VALUES($id,'$Pandadres','$Huisnummer','$Deel', '$Betaald', '$Nietbetaald' )";
if ($db->query($query) === TRUE) {
//echo 'users entry saved successfully';
}
else {
echo 'Error: '. $db->error;
}
$db->close();
$insert = mysqli_query($db, $query);
$_SESSION['msg'] = "Gebruiker opgeslagen";
header('location: overzichtlocatie.php'); // redirect to overzichtlocatie page after inserting
}
session_start();
//initialize variables
$naam = "";
$Achternaam = "";
$Bedrijfsnaam = "";
$Adres = "";
$Postcode = "";
$Woonplaats = "";
$Telefoon = "";
$Email = "";
$id = 0;
$Betalingsperiode= "";
$Bedragperperiode = "";
// connect to database
$db = mysqli_connect("xxxxxxxx","xxxxxxx","xxxxx","xxxxxx");
// if Opslaan button is clicked
if (isset($_POST["Opslaan"])){
$naam = $_POST["Naam"];
$Achternaam = $_POST["Achternaam"];
$Bedrijfsnaam = $_POST["Bedrijfsnaam"];
$Adres = $_POST["Adres"];
$Woonplaats = $_POST["Woonplaats"];
$Postcode = $_POST["Postcode"];
$Telefoon = $_POST["Telefoon"];
$Email = $_POST["E-mail"];
$Betalingsperiode = $_POST["Betalingsperiode"];
$Bedragperperiode = $_POST["Bedragperperiode"];
$query = "INSERT INTO Info (id, Naam,Achternaam,Bedrijfsnaam, Adres,Postcode,Woonplaats, Telefoon, Email, Betalingsperiode, Bedragperperiode) VALUES($id,'$naam','$Achternaam','$Bedrijfsnaam','$Adres','$Postcode','$Woonplaats','$Telefoon','$Email','$Betalingsperiode','$Bedragperperiode')";
if ($db->query($query) === TRUE) {
//echo 'users entry saved successfully';
}
else {
echo 'Error: '. $db->error;
}
$db->close();
$insert = mysqli_query($db, $query);
$_SESSION['msg'] = "Gebruiker opgeslagen";
header('location: Deleteedit.php'); // redirect to deleteedit page after inserting
}
There is so much wrong with this code, basically everything. It needs to be completely re-written.
I would suggest you start with this PDO tutorial.
https://phpdelusions.net/pdo
But it works, and i only need to know how to insert it in the same id, the main id is the table ‘Info’.
That is the worst possible response you could ever make in the programming world. You obviously have no intention of learning. Good luck finding anyone to spend their time on you for free.
I am a beginner in programming, why can’t you just help me out? I only need to know how.
When you were asked what the high level overview is of what you are doing, your reply didn’t answer that, you just dumped your code on the forum.
So, I’ll try again - what is the work-flow for this process? Someone sits down in front of a computer and what is the first step they do? What comes next? Who enters the ‘location’ data? Who enters the ‘info’ data (which is poorly named as it appears to be user/renter data)? Who selects a location?
And in case this helps (google translation of the above) - wat is de workflow voor dit proces? Iemand gaat achter een computer zitten en wat is de eerste stap die ze doen? Wat volgt? Wie voert de ‘locatiegegevens’ in? Wie voert de ‘info’-gegevens in (die slecht wordt genoemd omdat het gebruikers- / huurdersgegevens lijken te zijn)? Wie selecteert een locatie?
I am making a site for my school project. In this project I need to have a login page, After I log in. I have a live date on the middle of the screen, and I have a sidebar. On the sidebar there are 3 different buttons. The first button is for the table info, where I put the name, address etc. The second button is the table lokatie, where I add the location data. And the last button is for sending a reminder mail to the user. I am the only one who has access to this page.