DB ERROR: SQL syntax;

Asked

Viewed 41 times

2

I’m trying to create a temporary table with data from football teams, but I keep getting this error:

DB ERROR: You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the right syntax to use near ) and t.situacaojogador = 'active'

Can anyone help me understand what’s wrong? Follow my code.

$sql = "select codtime from jogador where codjogador=" . $_SESSION['codjogador'] . ";";
$rst = my_query($connR, $sql);
if(count($rst) > 0) {
    $codtimejogadorlogado = $rst[0]['codtime'];
} else {
    $codtimejogadorlogado = -1;
}

if($codtimejogadorlogado == '') {
    $codtimejogadorlogado = '-1';
}


$sql = "create temporary table tmptime as
    (select t.codtime, t.nome, j.codjogador
    from time t
    left join jogador j on j.codtime=t.codtime
    where j.codtime in ($codtimejogadorlogado) and t.situacaojogador = 'ativo');";
my_execute($connR, $sql);

Solved, I put another if to check if the codtime was empty. Updated code.

  • 1

    Yes... when a player leaves a team I change this value to 'inactive''

  • What version of MySQL that you are using?

  • use version 5.7.14

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.