0

I'm trying to transfer the clientid of a user after it has logged in into the system. Although I didn't manage to accomplish that.

The error I get is:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)

My code is:

session_start();

if(isset($_SESSION['Username']) && !empty($_SESSION['Username'])) {
    echo 'Set and not empty, and no undefined index error!';
}


$Server = "mydb";
$user = "user";
$password = "password";
$database = "database";
$table = "users";

$connectionInfo = array( "Database"=>$database,"UID"=>$user, "PWD"=>$password);
$link = sqlsrv_connect($Server, $connectionInfo);

$query = "SELECT \"clientid\" FROM \"users\" WHERE \"Username\" = '.$_SESSION['Username']'";

if($result = $mysqli->query($query)){

    While($row = $result->fetch_assoc()){
        echo "<b>User ID:</b>".row['clientid'];
    }
    $result->free();
}
else
{
    echo "No results found";
}

?>
<form action="#" method="post">
    <div class="form-group">
        <label>Company's Name: <?php echo $_SESSION["clientid"];?></label>


    </div>

And my login.php file is:

<?php

session_start();

$inputuser = $_REQUEST['Username'];
$inputpass = $_REQUEST['Password'];

$Server = "mydb";
$user = "user";
$password = "parrword";
$database = "database";
$table = "users";

$connectionInfo = array( "Database"=>$database,"UID"=>$user, "PWD"=>$password);
$link = sqlsrv_connect($Server, $connectionInfo);

if ($link === false) {
    echo "Connection failed. \n";
    die(print_r(sqlsrv_errors(), true));
}

$query = "SELECT \"Username\" FROM \"users\" WHERE \"Username\" = '$inputuser'";
$querypass = "SELECT \"Password\" FROM  \"users\" WHERE \"Password\"  ='$inputpass'";

$result = sqlsrv_query($link,$query);


if ($result === false) {
    die(print_r(sqlsrv_errors(), true));
}

$resultpass = sqlsrv_query($link,$querypass);

if ($resultpass === false) {
    die(print_r(sqlsrv_errors(), true));
}

$row = sqlsrv_fetch_array($result);
$rowpass = sqlsrv_fetch_array($resultpass);

$serveruser = $row["Username"];
$serverpass = $rowpass["Password"];


if ($serveruser And $serverpass) {

    $_SESSION["Username"] = $_REQUEST["Username"];

    header('Location: index.php');

}

else {  

    header('Location: FailedPage.html');

}

?>

Any help is useful!

Thank you!

jarlh
  • 42,561
  • 8
  • 45
  • 63

1 Answers1

0

No need for help i have managed to fix my problem and it was quite simple i just messed up the SESSION part.

I basically create a query into my login.php file to fetch the clientid with checking the username i have given from the login page

Then i set my SESSION to be equal with the clientid and in the index.php i just called the SESSION and it work.

I would like to thank anyone who tried to reply to my question.