Jump to content

Sqlite query from PHP returns wrong result


Recommended Posts

I have a table korisnici in SQLite with INTEGER field aktivan that can have only 0 or 1 value (CHECK constraint).

Field aktivan has value 0 but PHP returns value 1, why? Is this a bug?

This is PHP code that I am running:

 $sql = "SELECT ime, aktivan FROM korisnici WHERE lower(ime) = '" . $ime . "'" . " AND sifra = '" . $_POST["sifra"] . "'";
                
$result = $db->query($sql);
$row = $result->fetchArray(SQLITE3_ASSOC);

$row['aktivan'] = 1 but in table the value is 0.

When I run same query in DB Browser for SQLite I get correct value 0.

Is this a bug?

Link to post
Share on other sites

There is a bug, but it is not with PHP or SQLite.

Echo out the $sql and try that directly. Some value somewhere, either $ime or in $_POST or in your database, is not what you think it is.

Link to post
Share on other sites

I am little bit embarrassed to say, but there was a next line:

if($row['aktivan']=1)

Obviously, = should be ==  :shy:

Sorry, I will take 🔨 and accelerate it towards my  :huh:

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.