javascript - Cannot access cookie created by js using php -
i have began learn how use cookies , i'm sorry if answer simple. attempting create mysql database name js variable. this, attempting save variable cookie:
document.cookie = "test=" + variable;
i try cookie , save php variable executed:
<?php // define set variables $servername = "localhost"; $username = "root"; $password = ""; // input variables $test = $_cookie["test"]; // create connection $conn = mysqli_connect($servername, $username, $password); // check connection if (!$conn) { die("error: " . mysqli_connect_error()); } // sql create table $sql = "create database `$test`"; if (mysqli_query($conn, $sql)) { header("location: index.html"); exit; } else { echo "error: " . mysqli_error($conn); } mysqli_close($conn); ?>
i have tried creating cookie via php testing purposes:
<?php setcookie("test","variable"); ?>
when try access cookie created js clains index undefined runs when create cookie php thanks
remove spaces between "test=" + variable;
<script> var variable = "hello"; document.cookie = "test="+variable; </script> <?php $test = $_cookie["test"]; echo $test; ?>
Comments
Post a Comment