I simply have a query :
$username=shell_exec("echo %username%" ); //Give Qsr042
$Name=mysqli_fetch_array(mysqli_query($db,'SELECT * FROM user WHERE Login like "'.$username.'"'))['Name']; //Doesn't work
But when i do a echo gettype($Name);
, it says it's NULL.
In mysql I have 'Qsr042' as Login because if my query is :
$Name=mysqli_fetch_array(mysqli_query($db,'SELECT * FROM user WHERE Login like "Qsr042"'))['Name']; //Works
Now it simply works. Everything is a string so it should work... What have i missed ?
I know why it didn't work. I used $username=trim(shell_exec('echo %username%'))
and it worked. I'm not sure why but i won't complain. Thank you for trying helping me
shell_exec will execute the shell commands not PHP functions e.g.
$output = shell_exec('ls -lart'); echo "
$output";
Because you've got a return at the end.
Do a rtrim()
:
$username=shell_exec("echo %username%" ); //Give Qsr042 (with
)
$username=rtrim($username); //Give Qsr042
$Name=mysqli_fetch_array(mysqli_query($db,'SELECT * FROM user WHERE Login like "'.$username.'"'))['Name'];