[英]php and html form in single file
我想知道包含php代码和html表单的php文件是否存在问题。 例如:在文件的第一部分将是:
<?php ...
?>
<html>...<form action = "current file"> ..... </form>
</html>
该操作将引用此当前文件的名称。
还是我必须将扩展名为.php的文件中的php代码和扩展名为.html的文件中的html代码分开?
自己进行测试-可以。 您还可以在HTML标记内使用PHP,因为只要客户端发送请求,PHP就会在服务器端加载。
客户端发送请求->服务器获取请求并加载.php文件->服务器加载php,执行php,然后用返回的文本替换所有php对象,否则什么都不做->客户端获取具有以下内容的文件通过服务器加载(和编辑)
注意:如果将PHP与HTML结合使用,则文件需要扩展名.php,因为HTML最初不支持PHP标记。
这是同一文件中php和html表单的示例。 当然文件扩展名需要是.php
您只需要将' action =“当前文件” '更改为' action =“” '
的index.php
<?php
if(isset($_POST['submit'])) {
// The things that needs to be checked and executed WHEN submitted.
$email = htmlspecialchars($_POST['Email']);
$email = strip_tags($email);
$password = htmlspecialchars($_POST['Password']);
$password = strip_tags($password);
//SQL STUFF
if ($email === $row['email'] && $password === $row['password']) {
$_SESSION['uuid'] = $row['uuid'];
header("Location: profile.php?id=". $row['uuid'] ."");
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>My Form</title>
</head>
<body>
<form action="" method="POST">
<input type="email" name="Email" placeholder="Email..." required>
<input type="password" name="Password" placeholder="Password..." required>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.