Click here to Skip to main content
15,895,980 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
so I have this get request on reservation.php

<h2>Reserveren <?php echo $_GET['naam'];?>

'
on this page I have a form that users can fill in. if they hit submit they go to reservationback.php and this will insert all information in the db

now I want to also insert the ID that corresponds with the $_GET naam (a.k.a name) that I have on reservation.php
how do I do this?

reservationback.php
<?php
include "config.php";
if ($_POST['submit']){
    $naam =  $_POST['naam'];
    $email = $_POST['email'];
    $telefoonnummer = $_POST['telefoonnummer'];
    $huis_Naam = "huisnaam"; // This is where I want the information from the $_GET request

    $sql = "INSERT INTO huurder (naam, email, telefoonnummer, huis_Naam) VALUES (?, ?, ?, ?)"; 
    if($stmt = $conn->prepare($sql)){
        $stmt->bind_param('ssis', $naam, $email, $telefoonnummer, $huis_Naam);
        if(!$stmt->execute())
        {
            echo 'Het uitvoeren van de query is mislukt: '.$stmt->error.' in query: '.$sql;
        }else{
            echo "Het uitvoeren was een succes!";
        }
    }
}else{
    echo "random test";
}


What I have tried:

things I tried searching
post my $get to another page php

$_get to another page PHP

I also tried $huis_naam = $_GET['naam']; but that gives undefined array key (obviously because I'm not putting naam in to the url)
Posted
Updated 23-May-22 2:08am

1 solution

One way of doing this would be to simply have a hidden input element in the form. When the form is submitted, that would be sent across as part of the $_POST:

PHP
// Form
<form action=".." method="..">
  <input type="hidden" name="naam" value="..">
</form>

// PHP
<?php

$naam = $_POST['naam'];
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900