How to add more fields in my simple form i mean i wanna add like username,email , subject , subject 2 , subjet 3 .. just more fields in the form and thats all
<!DOCTYPE html>
<html>
<head>
<title>Store form data in .txt file</title>
</head>
<body>
<form method="post">
Enter Your Text Here:<br>
<input type="text" name="textdata"><br>
<input type="submit" name="submit">
</form>
</body>
</html>
<?php
if(isset($_POST['textdata']))
{
$data=$_POST['textdata'];
$fp = fopen('data.txt', 'a');
fwrite($fp, $data, $data2);
fclose($fp);
}
?>
CodePudding user response:
In the HTML form
<form method="post">
Enter Your Text Here:<br>
<input type="text" name="textdata"><br>
<!-- New fields -->
<input type="text" name="subject"/>
<input type="text" name="subject2"/>
<input type="submit" name="submit">
</form>
In the PHP code
$subject = $_POST['subject'];
$subject2 = $_POST['subject2'];
Additional notes : Taking form data directly like the above is risky. You need to sanitize the input values.
E.g.
$subject = addslashes($_POST['subject']);
CodePudding user response:
In the php form or html form, you can use the code below
<form method="POST">
<label>Enter Your Text Here:</label>
<!-- New fields form -->
<input type="text" name="username"/>
<input type="text" name="email"/>
<input type="text" name="subject"/>
<input type="text" name="subject2"/>
<input type="text" name="subjet3"/>
<input type="submit" name="submit">
</form>
Code processed by php in below
$username = $_POST['username'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$subject2 = $_POST['subject2'];
$subjet3 = $_POST['subjet3'];