If I try this, I get an error:
if($content[$weeknr] == 0) {
$sql5 = 'UPDATE logon_times_20BECW, allstudents20BE SET logon_times_20BECW.? = allstudents20BE.logon_time WHERE logon_times_20BECW.studentnr = ?';
$mystmt5 = $pdo->prepare($sql5);
$mystmt5->execute([$weeknr, $studentnr]);
}
The error is:
SQLSTATE[42000]: Syntax error or access violation: 1064 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 '‘Week2’ = allstudents20BE.logon_time WHERE logon_times_20BECW.studentnr = ‘20250’ at line 1
If I do this, everything is fine:
if($content[$weeknr] == 0) {
$sql5 = 'UPDATE logon_times_20BECW, allstudents20BE SET logon_times_20BECW.' . $weeknr . ' = allstudents20BE.logon_time WHERE logon_times_20BECW.studentnr = ?';
$mystmt5 = $pdo->prepare($sql5);
$mystmt5->execute([$studentnr]);
}
The first placeholder, $weeknr causes the problem. Does anyone know why?
I have other INSERT commands where I have maybe 50 placeholders, no problem.
Maybe it is the . directly before the placeholder?? I tried escaping the . but that didn’t work either.
logon_times_20BECW.?