代码在单独的文件中有效但在包含在相同的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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<?php
$connect=mysqli_connect("127.0.0.1","root","notmention","mysite");
if (mysqli_connect_errno($connect))
{
$txt="Failed to connect to MySQL: " . mysqli_connect_error();
}
$txz="s";
?>
</head>
<body background="images/background.PNG">
<div align="center">
<form action="register.html" enctype="multipart/form-data" method="post" >
<span style="color:#399">Create Account</span><br />
<input type="text" name="username" placeholder="Username" /><br />
<input type="text" name="password" placeholder="password" /><br />
<input type="text" name="email" placeholder="email" /><br />
<input type="submit" value="Submit" /><br />
</form>
</div>
<div><?php echo $txt ?></div><br />
<div><?php echo $txz ?></div><br />
</body>
</html>
答案 0 :(得分:0)
您需要使用 .php 扩展程序保存,而不是 .html