我对 PHP 完全陌生,随着我的高中学位临近,我决定为我们的年鉴中的个人描述制作一个 HTML 表单。但是当我的 PHP 文件处理表单 POST 时,我无法弄清楚如何分离不同的输入,它只是在一行中输出所有内容。我的 PHP 代码是这样的
<?php
$filename = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 6) . '.txt';
if ( !file_exists($filename) ) {
//File put contents stuff here
if(isset($_POST['fname']))
{
$data=$_POST['fname'];
$fp = fopen($filename, 'a');
fwrite($fp, $data);
}
if(isset($_POST['lname']))
{
$data=$_POST['lname'];
$fp = fopen($filename, 'a');
fwrite($fp, $data);
}
}
?>
我的 HTML 代码是:
<!DOCTYPE html>
<html>
<head>
<title>Erstelle deinen Steckbrief</title>
<meta charset="UTF-8">
<meta name="viewport" content="size=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=7">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="all">
<header>
<div id="ueberschrift">
<h1>Erstelle deinen Steckbrief für die Abizeitung</h1>
<p>Dies ist das Formular für das erstellen deiner Seite für die Abizeitung</p>
</div>
</header>
<div class="form">
<form name="" method="post" action="upload.php">
<label for="fname">Vorname:</label><br>
<input type="text" name="fname" id="fname"><br>
<br>
<label for="lname">Nachname:</label><br>
<input type="text" name="lname" id="lname"><br>
<br>
<label for="dateofbirth">Geburtsdatum:</label><br>
<input type="text" name="dateofbirth" id="dateofbirth"><br>
我将从 HTML 中删除上传图片代码,因为它似乎也不起作用。它甚至不再存在于 PHP 文件中。
Smart猫小萌
慕森卡
aluckdog
郎朗坤