PHP transfer variables between PHP includes in the same page

118
February 06, 2022, at 03:20 AM

I have index.php page where there is the date.php php include form. After add dates and user click next btn then date.php inlcude changed to personal.php innclude form where user will add his personal info and after, user click btn and his personal info + dates I want to save this data in database. The code works just the dates are not transferred to the 2nd php include.

index.php

<?php require_once "controllerUserData.php"; ?>
<?php
$scr = "";
if (isset($_GET["scr"])) $scr = $_GET["scr"];
  
switch ($scr)
{
    case "dat":
        showDates();
        break;
    case "per":
        showPersonal();
        break;
    default:
        showDates(); //it will show DATES form if no option was selected
}
function showDates()
{
    include("dates.php"); 
?>
<?php
}
function showPersonal()
{
    include("personalinfo.php");
?>

<?php
}
?>

dates.php

   
<form class="container3" action="y.php?scr=per" method="POST" autocomplete="">
<div class="form-label-group">
<input type="text" id="inputCheckin" style="flex-direction: row;" class="form-control" placeholder="Check-in" name="checkin" autocomplete="off" onfocus="(this.type='date')" onblur="if(!this.value) this.type='text'" required>
<label for="inputCheckin">Check-in</label>
</div>
<section class="horline"></section>
<div class="form-label-group">
<input type="text" id="inputCheckout" style="flex-direction: row;" class="form-control" placeholder="Check-out" name="checkout" autocomplete="off" onfocus="(this.type='date')" onblur="if(!this.value) this.type='text'" required>
<label for="inputCheckout">Check-out</label>
</div>

<footer class="container__footer3">
<button class="next" id="next" type="submit" name="next">Next</button>
</footer>
</form>

personalinfo.php

<form class="container3" action="y.php?scr=per" method="POST" autocomplete="">
<div class="form-label-group">
<input type="text" id="inputFirstname" class="form-control" name="name" placeholder="Firstname" minlength="3" autocomplete="off" style="text-transform:uppercase" required>
<label for="inputFirstname">Firstname</label>
</div>

<div class="form-label-group">
<input type="text" id="inputLastname" class="form-control" name="lname" placeholder="Lastname" minlength="3" autocomplete="off" style="text-transform:uppercase"required>
<label for="inputLastname">Lastname</label>
</div>

<div class="form-label-group">
<input type="email" id="inputEmail" class="form-control" name="email" placeholder="Email address" autocomplete="off" style="text-transform:lowercase" required>
<label for="inputEmail">Email address</label>
</div>

<section class="horline"></section>
<div class="form-label-group">
<input type="number" id="inputMobilenumber" class="form-control" name="mnumber" minlength="8" placeholder="Mobile number"  autocomplete="off" required>
<label for="inputMobilenumber">Mobile number</label>
</div>
    <button class="next" id="next" type="submit" name="signup">Next</button>
</form>

controllerUserData.php

   <?php 
   session_start();
   require "connection.php";
   $email = "main@gmail.com";
   $name = "";
   $errors = array();
   
   //if user next button
   if(isset($_POST['next'])){
       header('location: y.php?scr=per');
   }
   
   
   
   //if user signup button
   if(isset($_POST['signup'])){
       $name = mysqli_real_escape_string($con, $_POST['name']);
       $lname = mysqli_real_escape_string($con, $_POST['lname']);
       $mnumber = mysqli_real_escape_string($con, $_POST['mnumber']);
   
       $checkin = mysqli_real_escape_string($con, $_POST['checkin']);
       $checkout = mysqli_real_escape_string($con, $_POST['checkout']);
   
       $email = mysqli_real_escape_string($con, $_POST['email']);
       $rescode = mysqli_real_escape_string($con, $_POST['rescode']);
   
      
       if(count($errors) === 0){
           $code = rand(999999, 111111);
           $rescode = uniqid();
           $resstatus = "WAIT";
           $status = "notverified";
           $insert_data = "INSERT INTO usertable (name, email, code, status, lname, checkin, checkout, mnumber, totalprice, rescode, resstatus )
                           values('$name' , '$email', '$code', '$status','$lname', '$checkin', '$checkout', '$mnumber', '$totalprice', '$rescode', '$resstatus')";
           $data_check = mysqli_query($con, $insert_data);
     
           }else{
               $errors['db-error'] = "Failed while inserting data into database!";
           }
       }
   
   }
?>
Rent Charter Buses Company
READ ALSO
React infinite loop - onClick inside a render calls setState()

React infinite loop - onClick inside a render calls setState()

Pretty new to ReactI'm having some problems rendering a button component

186
addEventListener for submits overrides all my submit functions

addEventListener for submits overrides all my submit functions

I have an infinite scrolling template that has logic to override the submit action of formsThe issue is when my loop runs through it attaches the last eventListener to all my submit forms which causes issues

31
Why is this class in PHP working so weirdly with interface? [closed]

Why is this class in PHP working so weirdly with interface? [closed]

Want to improve this question? Add details and clarify the problem by editing this post

103