PHP在Visual Studio代码中运行不正常
我今天开始学习PHP,我正试图复制我在youtube上看到的购物车教程 我复制的代码正确,但它不工作 我正在使用VisualStudio代码和XAMPP。PHP似乎安装正确,因为当我在cmd上键入“PHP-v”时,它会显示实际版本 当我在localhost上运行iindex.php时,它会打印一个错误,比如第6、7、8行的错误,以及屏幕上看到的所有这些红线。我花了10个小时试图解决这个问题,但我就是做不到 也许你们中的一些人能帮我PHP在Visual Studio代码中运行不正常,php,Php,我今天开始学习PHP,我正试图复制我在youtube上看到的购物车教程 我复制的代码正确,但它不工作 我正在使用VisualStudio代码和XAMPP。PHP似乎安装正确,因为当我在cmd上键入“PHP-v”时,它会显示实际版本 当我在localhost上运行iindex.php时,它会打印一个错误,比如第6、7、8行的错误,以及屏幕上看到的所有这些红线。我花了10个小时试图解决这个问题,但我就是做不到 也许你们中的一些人能帮我 这是iindex.php文件 购物车 请参见 关于“He
这是iindex.php文件
购物车
请参见
关于“Heredoc”
祝你好运问题在于引用,可能是表单的错误操作
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;
}
函数组件(){
$元素=你的报价被弄乱了。因为你使用双引号来引用你的字符串,PHP将解释你的字符串中间的任何双引号作为结束引号,或者用单引号引用你的字符串,或者在你的字符串中逃出双引号。
<?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>
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;
}