0
<script>
  let checked = <?php echo $row["restriction"] ?>;
  console.log(checked);
</script>

When I was using a JS variable with let to store a php value, this output appears with errors:

1
userManage.php:88 Uncaught SyntaxError: Identifier 'checked' has already been declared (at userManage.php:88:49)
userManage.php:109 Uncaught SyntaxError: Identifier 'checked' has already been declared (at userManage.php:109:49) 
userManage.php:130 Uncaught SyntaxError: Identifier 'checked' has already been declared (at userManage.php:130:49)

The console.log only runs once then the three other values get an error.

After replacing let -> var, then there's clearly nothing wrong

<script>
  var checked = <?php echo $row["restriction"] ?>;
  console.log(checked);
</script>

Output:

1
1
1
0
0
7
  • 1
    developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Commented Apr 7 at 8:24
  • 2
    You haven't shown it, but it seems likely you are using this code in a PHP loop. Therefore it will generate multiple JS statements like this: let checked = ... in the page. As C3roe says, you cannot declare multiple variables using the same name in the same scope, if you declare them with let. Commented Apr 7 at 8:26
  • 1
    stackoverflow.com/a/18528925/295783 Commented Apr 7 at 11:32
  • 1
    @deceze Looking at the sample output the values appear to be numeric 1s and 0s, so I don't think they need quote marks adding. The value isn't text, and the word checked isn't output by PHP as far as I can make out. If that was happening, the error would be different than the one the OP is reporting. Commented Apr 7 at 12:47
  • 1
    @ADyson Ah, you're probably right. Commented Apr 7 at 13:02

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.