Syntax error unexpected token class php

First solution:

echo "<div class='col-md-12'>";
    echo "<div class='widget'>";
        echo "<header class='widget-header'>";
            echo "<h4 class='widget-title'>Chart Final Association Rule</h4>";
        echo "</header>";
        echo "<hr class='widget-separator'>";
        echo "<div class='widget-body'>";
            echo "<div data-plugin='chart' style='height:300px' data-options='{\"tooltip\":{\"trigger\":\"axis\"},\"legend\":{\"data\":[\"as\"]},\"calculable\":true,\"xAxis\":[{\"type\":\"category\",\"data\":[\"11\"]}],\"yAxis\":[{\"type\":\"value\"}],\"series\":[{\"name\":\"Sale\",\"type\":\"bar\",\"data\":[2,4.9,7,23.2,25.6,76.7,135.6,162.2,32.6,20,6.4,3.3],\"markPoint\":{\"data\":[{\"type\":\"max\",\"name\":\"Max\"},{\"type\":\"min\",\"name\":\"Min\"}]},\"markLine\":{\"data\":[{\"type\":\"average\",\"name\":\"Average\"}]}},{\"name\":\"Market\",\"type\":\"bar\",\"data\":[2.6,5.9,9,26.4,28.7,70.7,175.6,182.2,48.7,18.8,6,2.3],\"markPoint\":{\"data\":[{\"name\":\"Max\",\"value\":182.2,\"xAxis\":7,\"yAxis\":183,\"symbolSize\":18},{\"name\":\"Min\",\"value\":2.3,\"xAxis\":11,\"yAxis\":3}]},\"markLine\":{\"data\":[{\"type\":\"average\",\"name\":\"Average\"}]}}]}'>";
            echo "</div>";
        echo "</div>";
    echo "</div>";
echo "</div>";

Second solution:

?>
    <div class='col-md-12'>
        <div class='widget'>
            <header class='widget-header'>
                <h4 class='widget-title'>Chart Final Association Rule</h4>
            </header>
            <hr class='widget-separator'>
            <div class='widget-body'>
                <div data-plugin='chart' style='height:300px' data-options='{\"tooltip\":{\"trigger\":\"axis\"},\"legend\":{\"data\":[\"as\"]},\"calculable\":true,\"xAxis\":[{\"type\":\"category\",\"data\":[\"11\"]}],\"yAxis\":[{\"type\":\"value\"}],\"series\":[{\"name\":\"Sale\",\"type\":\"bar\",\"data\":[2,4.9,7,23.2,25.6,76.7,135.6,162.2,32.6,20,6.4,3.3],\"markPoint\":{\"data\":[{\"type\":\"max\",\"name\":\"Max\"},{\"type\":\"min\",\"name\":\"Min\"}]},\"markLine\":{\"data\":[{\"type\":\"average\",\"name\":\"Average\"}]}},{\"name\":\"Market\",\"type\":\"bar\",\"data\":[2.6,5.9,9,26.4,28.7,70.7,175.6,182.2,48.7,18.8,6,2.3],\"markPoint\":{\"data\":[{\"name\":\"Max\",\"value\":182.2,\"xAxis\":7,\"yAxis\":183,\"symbolSize\":18},{\"name\":\"Min\",\"value\":2.3,\"xAxis\":11,\"yAxis\":3}]},\"markLine\":{\"data\":[{\"type\":\"average\",\"name\":\"Average\"}]}}]}'>
                </div>
            </div>
        </div>
    </div>
<?php

Problems fixed:

  • Keys without quotes are not valid.
  • Values wrapped in single quotes are not valid.

im trying to create a basic login page and after checking username and password and navigating to next page i get this error on the page it suppose to navigate to and the section of code its referring too

Parse error: syntax error, unexpected token ";" in C:\xampp\htdocs\bubbleandbalm\index.php on line 4
<?php

session_start();

if(isset($_SESSION['id']) && (isset($_SESSION['user_name'])){

?>

this is the full code for that page aswell

<?php
session_start();
if(isset($_SESSION['id']) && (isset($_SESSION['user_name'])){
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" >
        <title>RedStore | Ecommerce Website Design</title>
        <link rel="stylesheet" href="style.css">
        <link rel="preconnect" href="https://fonts.gstatic.com">
        <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@200;500;600;700&display=swap" rel="stylesheet"> 
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome//css/fontawesome.min.css">
    </head>
    <body>
    <div class="header">
    <div class="container">
        <div class="navbar">
            <div class="logo">
                <img src="images/logo.png" width="125px">
            </div>
            <nav>
                <ul id="MenuItems">
                    <li><a href="">Home</a></li>
                    <li><a href="">Products</a></li>
                    <li><a href="">About</a></li>
                    <li><a href="">Contact Us</a></li>
                    <li><a href="">Account</a></li>
                </ul>
            </nav>
            <img src="images/cart.png" width="30px" height="30px" >
            <img src="images/menu.png" class="menu-icon" onclick="menutoggle()">
        </div>
        <div class="row">
            <div class="col-2">
                <h2>Give Your Workout<br>A New Style?</h2>
                <p>Success isnt always about greatness. It's about 
                    consistency. consistent<br>hard work gains success, Greatness 
                    will come.
                </p>     
                <a href="" class="btn">Explore Now &#8594;</a>    
            </div>
            <div class="col-2">
                <img src="images/image1.png">
            </div>
            
        </div>   
    </div>
    </div>

    <!--featured categories-->
    <div class="categories">
        <div class="small-container">
            <div class="row">
                <div class="col-3">
                    <img src="images/category-1.jpg">
                </div>
                <div class="col-3">
                    <img src="images/category-2.jpg">
                </div>
                <div class="col-3">
                    <img src="images/category-3.jpg">
                </div>   
            </div>
        </div>
    </div>

    <!--featured products-->

    <div class="small-container">
        <h2 class="title">Featured Products</h2>
        <div class="row">
            <div class="col-4">
                <img src="images/product-1.jpg">
                <h4>Red Printed T-Shirt</h4>
                <p>£25.00</p>
            </div>
            <div class="col-4">
                <img src="images/product-2.jpg">
                <h4>Red Printed T-Shirt</h4>
                <p>40.00</p>
            </div>
            <div class="col-4">
                <img src="images/product-3.jpg">
                <h4>Red Printed T-Shirt</h4>
                <p>£30.00</p>
            </div>
            <div class="col-4">
                <img src="images/product-4.jpg">
                <h4>Red Printed T-Shirt</h4>
                <p>£20.00</p>
            </div>
        </div>

        <!--latest products-->
        <h2 class="title">Latest Products</h2>
        <div class="row">
            <div class="col-4">
                <img src="images/product-5.jpg">
                <h4>Red Printed T-Shirt</h4>
                <p>£25.00</p>
            </div>
            <div class="col-4">
                <img src="images/product-6.jpg">
                <h4>Red Printed T-Shirt</h4>
                <p>40.00</p>
            </div>
            <div class="col-4">
                <img src="images/product-7.jpg">
                <h4>Red Printed T-Shirt</h4>
                <p>£30.00</p>
            </div>
            <div class="col-4">
                <img src="images/product-8.jpg">
                <h4>Red Printed T-Shirt</h4>
                <p>£20.00</p>
            </div>
            <div class="row">
                <div class="col-4">
                    <img src="images/product-9.jpg">
                    <h4>Red Printed T-Shirt</h4>
                    <p>£25.00</p>
                </div>
                <div class="col-4">
                    <img src="images/product-10.jpg">
                    <h4>Red Printed T-Shirt</h4>
                    <p>40.00</p>
                </div>
                <div class="col-4">
                    <img src="images/product-11.jpg">
                    <h4>Red Printed T-Shirt</h4>
                    <p>£30.00</p>
                </div>
                <div class="col-4">
                    <img src="images/product-12.jpg">
                    <h4>Red Printed T-Shirt</h4>
                    <p>£20.00</p>
                </div>
            </div>
        </div>
    </div>
    <!--offer-->
    <div class="offer">
        <div class="small-container">
            <div class="row">
                <div class="col-2">
                    <img src="images/exclusive.png" class="offer-img">
                </div>
                <div class="col-2">
                    <p>Exclusively Available on RedStore</p>
                    <h2>Smart Band 4</h2>
                    <small>TheMi Smart Band 4 features a 39.9%
                        larger AMOLED color full-touch display with
                        adjustable brightness, so everything is clear
                         as can be.
                    </small>
                    <a href="" class="btn">Buy Now &#8594;</a>
                </div>
            </div>
        </div>
    </div>

    <!--Brands-->

    <div class="brands">
        <div class="small-container">
            <div class="row">
                <div class="col-5">
                    <img src="images/logo-godrej.png">
                </div>
                <div class="col-5">
                    <img src="images/logo-oppo.png">
                </div>
                <div class="col-5">
                    <img src="images/logo-coca-cola.png">
                </div>
                <div class="col-5">
                    <img src="images/logo-paypal.png">
                </div>
                <div class="col-5">
                    <img src="images/logo-philips.png">
                </div>
            </div>
        </div>
    </div>

    <!--footer-->

    <div class="footer">
        <div class="container">
            <div class="row">
                <div class="footer-col-1">
                    <h3>Download Our App</h3>
                    <p>Download Appfor Android<br>and IOS mobile phone.</p>
                    <div class="app-logo">
                        <img src="images/play-store.png">
                        <img src="images/app-store.png">
                    </div>
                </div>
                <div class="footer-col-2">
                    <img src="images/logo-white.png">
                    <p>Our purpose is to sustainably make the pleasure and<br>benefits of sports accessible to the many.</p>
                
                </div>
                <div class="footer-col-3">
                    <h3>Useful Links</h3>
                    <ul>
                        <li>Coupons</li>
                        <li>Blog Posts</li>
                        <li>Return Policy</li>
                        <li>Join Affiliate</li>
                    </ul>
                
                </div>
                <div class="footer-col-4">
                    <h3>Follow Us</h3>
                    <ul>
                        <li>Facebook</li>
                        <li>Twitter</li>
                        <li>Instagram</li>
                        <li>Youtube</li>
                    </ul>
                
                </div>
            </div>
            <hr>
            <p class="copyright">Copyright 2021 - Easy Tutorials</p>
        </div>
    </div>
    <!--js for toggle menu-->
    <script>
        var MenuItems = document.getElementById("MenuItems");
        MenuItems.style.maxHeight = "0px";
        function menutoggle(){
            if(MenuItems.style.maxHeight == "0px"){
                MenuItems.style.maxHeight = "200px";
            }
            else{
                MenuItems.style.maxHeight = "0px";
            }
        }
    </script>

    </body>
</html>

<?php
}
else{
    header("Location: account.php");
    exit();

}
?>

my login in page

<?php 
session_start();
include "db_conn.php";

if (isset($_POST['uname']) && isset($_POST['password'])){
    function validate($data){
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
        return $data;

    }
    $uname = validate($_POST['uname']);
    $pass  = validate($_POST['password']);

    if(empty($uname)){
        header("Location: account.php?error=User Name is required");
        exit();

    }
    else if (empty($pass)){
        header("Location: account.php?error=Password is required");
        exit();
    }
    else{
        $sql = "SELECT * FROM login WHERE user_name = '$uname' AND password = '$pass'";

        $result = mysqli_query($conn, $sql);

        if (mysqli_num_rows($result) === 1){
            $row = mysqli_fetch_assoc($result);
            if($row['user_name'] === $uname && $row['password'] === $pass){
                $_SESSION['user_name'] = $row['user_name'];
                $_SESSION['name'] = $row['name'];
                $_SESSION['id'] = $row['id'];
                header("Location: index.php");
                exit();
            }
            else{
                header("Location: account.php?error=Incorrect username or password");
                exit();
            }

        }
        else{
            header("Location: account.php?error=Incorrect username or password");
            exit();
        }
    }

}
else{
    header("Location: account.php");
    exit();
}
?>

db_conn page

<?php

$sname = "localhost";
$uname = "root";
$password = "";

$db_name = "users";

$conn = mysqli_connect($sname,$uname,$password, $db_name);

if (!$conn){
    echo "Connection failed!";
}
?>

How do I fix an unexpected token syntax error?

As you write your JavaScript application, the unexpected token error always occurs because JavaScript expected a specific syntax that's not fulfilled by your current code. You can generally fix the error by removing or adding a specific JavaScript language symbol to your code.

What is unexpected token in PHP?

Unexpected – This means the code is missing a character and PHP reaches the end of the file without finding what it's looking for. The error will include information at the end that explains what it saw that was unexpected.

What is syntax error unexpected token?

The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided. This might be a simple typo.

What is syntax error in PHP?

If the PHP code contains a syntax error, the PHP parser cannot interpret the code and stops working. For example, a syntax error can be a forgotten quotation mark, a missing semicolon at the end of a line, missing parenthesis, or extra characters.