0

I'm trying to bind the parameter "userShort" from my SESSION together with some other values into my pdo statement. But everytime I run it, it updates the user column with a NULL value while all other columns get updated with the correct value. Where is my mistake?

$stmt = $conn->prepare('UPDATE productionplanning 
                            SET '.$column.' = :value, 
                                lastChange = :timestamp, 
                                user = :worker 
                        WHERE idproductionplanning = :id');

$stmt->bindValue(':value', $value);
$stmt->bindValue(':timestamp', $timestamp);
$worker = $_SESSION['userShort'];
$stmt->bindParam(':worker', $worker, PDO::PARAM_STR, 4);
$stmt->bindValue(':id', $id);

When I var_dump my SESSION it shows that userShort really does have a value:

["userShort"]=> string(2) "MK"

The column is of the type VARCHAR(4) and I'm calling the UPDATE statement through ajax. Am I just stupid for not seeing my mistake? Also, I'm pretty new to php/pdo/mysql, so I appreciate every help even if it seems stupid to you.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
iMorces
  • 11
  • 3
  • Where exactly do you do the var_dump? Did you call session_start on the AJAX page? – Salman A Sep 27 '21 at 12:51
  • 2
    Why are you switching between `bindValue` and `bindParam`? – CBroe Sep 27 '21 at 12:53
  • @SalmanA I knew it was something stupid. The session_start was missing. Thanks so much for your help. – iMorces Sep 27 '21 at 12:54
  • @cBroe I'm stilling trying to figure out the difference between bindValue and bindParam and haven't had time yet to read more detailed about it. But I noticed that with bindValue I get an error while bindParam at least runs through even if the value isn't assigned. Gonna check that as the next step. – iMorces Sep 27 '21 at 12:55
  • There a question-answer-thread about the difference between the two here, https://stackoverflow.com/q/1179874/1427878 – CBroe Sep 27 '21 at 12:57

0 Answers0