$con = mysqli_connect('localhost','blabla','blabla','blabla'); $sql = mysqli_query($con,"SELECT data, content FROM sinc"); while ($result = mysqli_fetch_assoc($sql)) { echo $result['data'].": ".$result['content']."<br>"; //Данные выводятся echo "<script>localStorage.setItem("$result["data"]", "$result["data"]")</script>"; //Данные не сохраняются в localStorage. //Parse error: syntax error, unexpected '$result' (T_VARIABLE), expecting ',' or ';' } 
  • one
    You closed the double quote early. - vp_arth
  • moreover, the array element should be written in single quotes, since the variable is placed in double, or double escapes are inside - Alexey Shimansky
  • one
    echo "<script>localStorage.setItem(".$result['data'].", ".$result['data'].")</script>"; something like this can be ........ either like this: echo "<script>localStorage.setItem({$result['data']}, {$result['data']})</script>"; - Alexey Shimansky
  • Well or concatenation (dot operator . ) Use if you don’t want to write variables inside quotes - rjhdby
  • it is even better to use templates, and not to interfere with flies with cutlets. - teran

0