简体   繁体   English

HTML中的PHP不起作用

[英]Php in HTML doesn't work

Look, i have html with included php link but that doesn't work well.Information what was in html doesn't come to php page. 看,我有包含php链接的html,但是效果不佳。html中的信息无法进入php页面。 Please help with that. 请帮忙。

HTML CODE: HTML代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD
➝ XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/
➝ DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/
➝ 1999/xhtml" xml:lang="en"
➝ lang="en">
<head>
<meta http-equiv="Content-Type"
➝ content="text/html;
➝ charset=utf-8"/>
<title>Greetings!</title>
</head>
<body>
<!-- Script 3.6 - hello.html -->
<div><p>Click a link to say
➝ hello:</p>
<ul>
<li><a href="hello.php?
name=Michael">Michael</a></li>
<li><a href="hello.php?
name=Celia">Celia</a></li>
<li><a href="hello.php?
name=Jude">Jude</a></li>
<li><a href="hello.php?
name=Sophie">Sophie</a></li>
</ul>
</div>
</body>
</html>

PHP code: PHP代码:

    <!DOCTYPE html PUBLIC "-//W3C//DTD
➝ XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/
➝ DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/
➝ 1999/xhtml" xml:lang="en"
➝ lang="en">
<head>
<meta http-equiv="Content-Type"
➝ content="text/html;
➝ charset=utf-8"/>
<title>Greetings!</title>
</head>
<body>
<?php // Script 3.7 - hello.php
error_reporting (E_ALL | E_STRICT);
$name - $_GET['name'];
print "<p>Hello, <span
style=\font-weight:
bold;\">$name</span>!</p>";
?>
</body>
</html>

And this how it's look on web http://santa-monica.comli.com/hello.html 以及在网络上的外观http://santa-monica.comli.com/hello.html

http://santa-monica.comli.com/hello.php?name=Michael http://santa-monica.comli.com/hello.php?name=Michael

change your php code to this - 将您的PHP代码更改为此-

<!DOCTYPE html PUBLIC "-//W3C//DTD
➝ XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/
➝ DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/
➝ 1999/xhtml" xml:lang="en"
➝ lang="en">
<head>
<meta http-equiv="Content-Type"
➝ content="text/html;
➝ charset=utf-8"/>
<title>Greetings!</title>
</head>
<body>
<?php // Script 3.7 - hello.php
error_reporting (E_ALL | E_STRICT);
$name = $_GET['name'];
print '<p>Hello, <span style="font-weight:bold;">'.$name.'</span>!</p>';
?>
</body>
</html>

your link to the php page is working fine, your problem is where u define the name variable, you have a typo, instead of $name = $_GET['name']; 您到php页面的链接工作正常,问题是您在其中定义了名称变量,您有错字,而不是$name = $_GET['name']; you put $name - $_GET['name']; 你把$name - $_GET['name']; , dont worry this happens to the best of us, fix that and it should run smoothly, btw if you are testing your php code on an online server dont, because it is slower than on your pc, unless you are contacting an api, it doesnt work unless its executing online ,不要担心这种情况对我们最好的人会发生,请解决此问题,它应该可以平稳运行,顺便说一句,如果您正在在线服务器上测试php代码,请不要这样做,因为它比您的PC上速度慢,除非您正在联系api,除非它在线执行,否则不起作用

EDIT : 编辑:

change your code to this : 将您的代码更改为此:

<?php // Script 3.7 - hello.php
error_reporting (E_ALL | E_STRICT);
$name = $_GET['name'];
?>
<p>Hello, <span
style=\font-weight:
bold;\"><?php echo $name; ?></span>!</p>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM