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

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -