1

I am trying to make an update with a prepared statement, but it keeps updating the wrong value (2147483647). I can't figure out where this value is coming from. Here is my code:

$myID = 5;
$loginTokenNew = time() * rand(3, 33) * $myID;
$_SESSION['loginToken'] = $loginTokenNew;

$mysqli = connectToDB();
$stmt = $mysqli->prepare('UPDATE users SET token=? WHERE id=?') or die('Couldn\'t update user token');
$stmt->bind_param('ii', $loginTokenNew, $myID);
$stmt->execute();
$stmt->close();
$mysqli->close();

The weird thing is that the session variable takes the right value, but the "token field" in the db keeps taking the value: 2147483647

Is my prepared statement wrong somehow or could it have something to do with my db? the field "token" is a INT (255) field btw.

Langkiller
  • 3,377
  • 13
  • 43
  • 72

1 Answers1

4

2147483647 is the largest number a signed 32-bit (4-byte) INT can hold.

Change the field to a bigger type, such as BIGINT (or BIGINT UNSIGNED if the number is always positive), or to a string type, such as VARCHAR.

Sverri M. Olsen
  • 13,055
  • 3
  • 36
  • 52