0
I am trying to make the following query in the database through PHP:
SELECT * FROM nwpedidos WHERE `nomeUsuario` = 'Nome'
However, the 'Name' varies according to who makes the query, for this I pass a variable via javascript. The problem is that the query does not return anything if I use variable as in the example below, but if I use the full command as in the example above, everything works normally.
<script>
var a = getName();
function getName(){
var b = document.getElementById("LoginName1").innerText;
var res = b.split(":");
return res[1].trim();
}
</script>
<?php
require_once("connect.php"); //conectar no banco
$var = "<script>document.write(a);</script>"; //pegar o conteudo da variavel JS
$sql = "SELECT * FROM `nwpedidos` WHERE `nomeUsuario` = '" . $var . "'"; //consulta no banco (que não retorna nada)
$resultado = $MySQLi->query($sql) OR trigger_error($MySQLi->error, E_USER_ERROR);
while ($dado = $resultado->fetch_object()) {
?>
var_dump($var) face; and ve put here the result I believe the information inside the $var that is incorrect so it does not return anything!
– Lodi
Why not save user name in session?
– Vinicius De Jesus
var_dump had already tested, at first it’s right. 'string(35)'
– Gabriel Sarates
@Viniciusdejesus with cookies for example?
– Gabriel Sarates
@Gabrielsarates using Sessions, as you take the user name and save in
var a
?– Vinicius De Jesus
@Viniciusdejesus with javascript, the user is written in a span with Loginname1 ID.
– Gabriel Sarates