-2

I am trying to code a user system. I am having an issue with the activation part. I can select and insert data to my table but now I am trying to create an update statement and got stuck.

<?PHP
include "db_settings.php";
$stmt = $dbcon->prepare("UPDATE 'Kullanicilar' SET 'Aktivasyon' = ? WHERE 'KullaniciID'=?");
// execute the query
$stmt->execute(array('1','5'));

// echo a message to say the UPDATE succeeded
echo $stmt->rowCount() . " records UPDATED successfully";
?>

And I am getting error as:

"0 records UPDATED successfully".

This is my table; https://i.stack.imgur.com/0j2ta.png

enter image description here

I have tried by changing my 'Aktivasyon' type int to char but it also does not work.


EDIT: I am trying to make this a function;

function dataUpdate($tableName, $updateRow, $updateValue, $conditonRow, $conditionValue)
{
        include "db_settings.php";
        $q = $dbcon->prepare("UPDATE $tableName SET $updateRow= ? WHERE $conditonRow= ?");
        $q->execute(array($updateValue,$conditionValue));
}

I also try this :

          ...
        $q = $dbcon->prepare("UPDATE `$tableName` SET `$updateRow`= ? WHERE `$conditonRow`= ?");
        ...

How can I make this statement work?

Michele La Ferla
  • 6,775
  • 11
  • 53
  • 79
Ahmet Karabulut
  • 153
  • 1
  • 12

1 Answers1

-1

You are using wrong quotes. You are basically saying "update this table, set this string to something when the string KullaniciID equals the string 5" which of course never is true.

You should use backticks ` if you want to specify column names. Then your query would work. Usually you don't even need those, but for some reason MySQL world is always adding them.

So to clarify, this is a string: 'KullaniciID' and this is a column name: `KullaniciID`.

Also you should not send integers as strings. It causes extra conversions or even errors with more strict databases.

Sami Kuhmonen
  • 30,146
  • 9
  • 61
  • 74