[英]php and html form in single file
I wonder if there is a problem for a php file that contains php codes and html form. 我想知道包含php代码和html表单的php文件是否存在问题。 for example: in the file the first part would be:
例如:在文件的第一部分将是:
<?php ...
?>
<html>...<form action = "current file"> ..... </form>
</html>
The action will refer to the name of this current file. 该操作将引用此当前文件的名称。
or do I have to separate the php code in a file with extension .php, and html code in a file with extension .html? 还是我必须将扩展名为.php的文件中的php代码和扩展名为.html的文件中的html代码分开?
Test it on your own– You can. 自己进行测试-可以。 You can also use PHP inside of a HTML tag, because the PHP is loaded server-side whenever the client sends a request.
您还可以在HTML标记内使用PHP,因为只要客户端发送请求,PHP就会在服务器端加载。
Client sends request --> Server gets request and loads up the .php file --> Server loads the php, executes the php, and replaces all php objects with text that it returns, or nothing --> Client gets the file that has been loaded (and edited) via the server
客户端发送请求->服务器获取请求并加载.php文件->服务器加载php,执行php,然后用返回的文本替换所有php对象,否则什么都不做->客户端获取具有以下内容的文件通过服务器加载(和编辑)
Note: If you combine PHP with HTML, the file needs the extension .php because HTML does not originally support PHP tags. 注意:如果将PHP与HTML结合使用,则文件需要扩展名.php,因为HTML最初不支持PHP标记。
Here's an example for a php and html form in same file. 这是同一文件中php和html表单的示例。 Ofcourse the file extension needs to be .php
当然文件扩展名需要是.php
You just need to change ' action="current file" ' to ' action="" ' 您只需要将' action =“当前文件” '更改为' action =“” '
index.php 的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.