skip to Main Content

I started PHP today and I’m trying to copy a Shopping Cart Tutorial I’ve seen on youtube.

I copy the code correctly but it is not working.

I’m using Visual Studio Code and XAMPP. PHP seems to be installed correctly, because when I type “php -v” on cmd it shows the actual version.

When I run iindex.php on localhost it prints an error, like error on line 6,7,8 and all of these red lines you’re seeing on the screen. I spent 10h trying to solve that but I just couldn’t.

Maybe some of you can help me?

enter image description here

<?php
function component(){
    $element = "
<div class="col-md-3 col-sm-6 my-3 my-md-0">
                <form action="iindex.php;" method="post;">
                    <div class="card-shadow">
                        <div>
                            <img src="./upload/product1.png" alt="Image1" class="img-fluid card-img-top">
                        </div>
                        <div class="card-body">
                            <h5 class="card-title">Product1</h5>
                            <h6>
                                <i class="fas fa-star"></i>
                                <i class="fas fa-star"></i>
                                <i class="fas fa-star"></i>
                                <i class="fas fa-star"></i>
                                <i class="far fa-star"></i>
                            </h6>
                            <p class="card-text">
                                Some example text
                            </p>
                            <h5>
                                <small><s class="text-secondary">$519</s></small>
                                <span class="price">$599</span>
                            </h5>

                            <button type="submit" name="add" class="btn btn-warning my-3">Add to cart <i class="fas fa-shopping-cart"></i></button>

                        </div>
                    </div>
                </form>
            </div>
    ";
}
?>

This is the iindex.php fileenter image description here

<?php
require_once('./php/ccomponent.php')
?>


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>shopping cart</title>

    <!-- font awesome cdn -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.css" integrity="sha256-46qynGAkLSFpVbEBog43gvNhfrOj+BmwXdxFgVK/Kvc=" crossorigin="anonymous" />
    <!-- bootstrap cdn -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <!-- <link rel="stylesheet" href="sstyle.css"> -->
</head>

<body>

    <div class="container">
        <div class="row text-center py-5">
            <?php
            ccomponent();
            ?>
        </div>
    </div>

    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>

</html>

2

Answers


  1. The problem is with the quotes and maybe the mispelled action of the form.

     function component(){
        $element = <<<html
                <div class="col-md-3 col-sm-6 my-3 my-md-0">
                    <form action="index.php;" method="post;">
                        <div class="card-shadow">
                            <div>
                                <img src="./upload/product1.png" alt="Image1" class="img-fluid card-img-top">
                            </div>
                            <div class="card-body">
                                <h5 class="card-title">Product1</h5>
                                <h6>
                                    <i class="fas fa-star"></i>
                                    <i class="fas fa-star"></i>
                                    <i class="fas fa-star"></i>
                                    <i class="fas fa-star"></i>
                                    <i class="far fa-star"></i>
                                </h6>
                                <p class="card-text">
                                    Some example text
                                </p>
                                <h5>
                                    <small><s class="text-secondary">$519</s></small>
                                    <span class="price">$599</span>
                                </h5>
    
                                <button type="submit" name="add" class="btn btn-warning my-3">Add to cart <i class="fas fa-shopping-cart"></i></button>
    
                            </div>
                        </div>
                    </form>
                </div>
    html;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search