dimanche 1 août 2021

How to transfer the data stored in variable after a $_POST response to another file ? in PHP in API dev [duplicate]

I have created two files File_1.php and File_2.php , i am creating these for api developerment for my android app.Now I need to transfer the userName and companyName from file-1.php to file-2.php so that i can create a database.I know it will be lame to do this way but still i want to learn , just tell me how can i transfer the data to another file in this situation. I have used session but it give me this error ->

Parse error</b>: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or
variable (T_VARIABLE) or number (T_NUM_STRING) in <b>/opt/lampp/htdocs/digitalDukanApi/mobileCheck.php</b> on line
<b>32</b><br />

in File-2 .php , I get this error on using SESSION['companyName'] ?

File_1 .php

    <?php

session_start();


$serverName = "localhost";
$userName = "root";
$password = "";


//connection established
$conn = new mysqli($serverName , $userName , $password);



// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}


if(isset($_POST['user']) && isset($_POST['companyName'])){
    $user = $_POST['user'];
    $companyName = $_POST['companyName'];

    $_SESSION['user'] = $user;
    $_SESSION['companyName'] = $companyName;

}

//create the DB
$query = "CREATE DATABASE $user";

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

if($result == true){
    $response = "Inserted";
}
else{
    $response = "Not Inserted";
}

echo json_encode($response);

$conn->close();



?

File_2.php

>     <?php
> 
> session_start();
> 
> $serverName = "localhost"; $userName = "root"; $password = "";
> 
> 
> //connection established $conn = new mysqli($serverName , $userName ,
> $password);
> 
> //Select the database  mysqli_select_db($conn , $_SESSION['user']);
> 
> 
> 
> // Check connection if ($conn->connect_error) {   die("Connection
> failed: " . $conn->connect_error); }
> 
> if(isset($_POST['phoneNumber'])){   $ph = $_POST['phoneNumber']; }
> 
> //process the OTP
> 
> 
> 
> 
> $query = "CREATE TABLE $_SESSION['companyName'] (
>     id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
>     first_name VARCHAR(30) NOT NULL,
>     last_name VARCHAR(30) NOT NULL,
>     email VARCHAR(70) NOT NULL UNIQUE )";
> 
> $result = mysqli_query($conn ,$query);
> 
> if($result == true){   $response = "Created table"; } else{  
> $response = "Not Created"; }
> 
> echo json_encode($response);
> 
> 
> 
> 
> 
> 
> ?>



Aucun commentaire:

Enregistrer un commentaire