Home » Php » javascript – certificate.php:5 Uncaught ReferenceError: TEstasdasd is not defined

javascript – certificate.php:5 Uncaught ReferenceError: TEstasdasd is not defined

Posted by: admin February 25, 2020 Leave a comment

Questions:

my php code

<?php
if (isset($_POST['submit'])) {
    $name = $_POST['name'];
    $address = $_POST['address'];
    $fname = $_POST['fname'];
    $mname = $_POST['mname'];
    $all_info = $name . "<br>" . $address . "<br>" . $fname . "<br>" . $fname;
    // echo $all_info;
}

// echo $name,$email,$message;

?>

my js code

<script>

const name = <?php echo $name ?>;
console.log(name);
alert(name);


</script>

error

certificate.php:5 Uncaught ReferenceError: TEstasdasd is not defined

eror sources code

<script>

const name = TEstasdasd;
console.log(name);
alert(name);


</script>

I can’t fix my bugs can anyone help me?

How to&Answers:

const name = TEstasdasd; on this line you’re getting error. Because you didn’t define it anywhere and try to call that constant

Try as below.

const name = 'TEstasdasd';