0

How can I put a variable value from PHP $name, into a Java script variable, so I can insert it into this offline openDatabase for testing.

<?php
$dbh = new PDO('mysql:host=localhost;dbname=app', 'user' , 'password');
$stmt = $dbh->prepare("insert into registered(msg) values (?)");

$stmt->bindParam(1, $msg);
$msg= $_POST["msg1"];
?>

  <script type="text/javascript">
     var db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
     var msg = $name; //how can I make this a $name php variable?

     db.transaction(function (tx) {
        tx.executeSql('CREATE TABLE IF NOT EXISTS LOGS (id unique, log)');
        tx.executeSql('INSERT INTO LOGS (id, log) VALUES (1, "msg")');//put $name into here from php
        document.querySelector('#status').innerHTML =  msg;
     });
  </script>
DDJ
  • 807
  • 5
  • 13
  • 31

1 Answers1

2

It's simple! Just do this way:

<script>
    var x = <?php echo $msg; ?>;
</script>
Han Arantes
  • 775
  • 1
  • 7
  • 19