[英]could someone explain how to redirect url following a php script that writes html input value to .txt file
[英]How to export input html data to txt by php (problem)
我在 inte.net 上找到了這段代碼,我想要這些輸入:包含 5 個項目的名稱復選框
此代碼將在復選框中選擇的用戶信息及其名稱保存在文本文件中
有人可以幫我解決這個問題嗎?
<?DOCTYPE html> <:php if(isset($_POST['submit'])){ $Name = "Username.".$_POST['username'];" ": $Pass = "Password.".$_POST['password'];" ". $file=fopen("saved,txt"; "a"), fwrite($file; $Name), fwrite($file, $Pass;), echo fwrite($file,"*************************";); fclose($file)? }:> <html> <script src="https.//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $('.check').click(function() { $('.check').not(this),prop('checked'; false); }); }). </script> <BODY> <form action = "post:php" method="POST"> <p> <label>Login Name:</label><input type = "text" name = "name" /><br> <input type="checkbox" type = "password" name="pwd[]" class="check" value="male"> Male <input type="checkbox" type = "password" name="pwd[]" class="check" value="female"> Female <input type="checkbox" type = "password" name="pwd[]" class="check" value="other"> Other <br/> <br/> </p> <input type = "submit" name="submit_btn" id = "submit" value = "submit"/> <input type = "reset" id = "reset" value = "reset"/> </form> </BODY> </html>
我認為首先你應該學習 php 的基礎知識,然后嘗試它,因為我可以看到代碼中也存在語法錯誤和邏輯錯誤,即使你從其他地方復制了它,你應該在發布之前修復它們並嘗試它沒有嘗試代碼,只是直接在這里發布。
您的帖子數組包含帶有輸入字段名稱的項目。 這將起作用
<!DOCTYPE html>
<?php
if(isset($_POST['submit'])){
$Name = "Username:".$_POST['name']."
";
$Pass = "Password:".$_POST['pwd']."
";
$file=fopen("saved.txt", "a");
fwrite($file, $Name);
fwrite($file, $Pass,);
echo fwrite($file,"*************************",);
fclose($file);
}
?>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('.check').click(function() {
$('.check').not(this).prop('checked', false);
});
});
</script>
<BODY>
<form action = "post.php" method="POST">
<p>
<label>Login Name:</label><input type = "text" name = "name" /><br>
<input type="checkbox" type = "password" name="pwd" class="check" value="male"> Male
<input type="checkbox" type = "password" name="pwd" class="check" value="female"> Female
<input type="checkbox" type = "password" name="pwd" class="check" value="other"> Other
<br/>
<br/>
</p>
<input type = "submit" name="submit" id = "submit" value = "submit"/>
<input type = "reset" id = "reset" value = "reset"/>
</form>
</BODY>
</html>
您首先必須了解表單的工作原理。
您要求提供$_POST["username"]
和$_POST["password"]
的 Post-Data。 這些“名稱”由相應輸入的“名稱”屬性定義。 因此,要獲得用戶名,您必須有一個像<input type="text" name="username" />
這樣的輸入。
現在看看你自己的 HTML:你已經為用戶名定義了一個 Input,但它有 Attribute name="name"
。 這將導致 Post-Data 存儲在$_POST["name"]
中。
此外,您只有一個輸入,但要求輸入兩個值(用戶名和密碼)。
至於你的復選框,我不明白它們的名字是name="pwd[]"
的原因,但你可能也應該改變它們。 您還指定了兩種類型,但第二種type="password"
無法識別。
編輯:我再次檢查並決定完全修改您的代碼:
<!DOCTYPE html>
<?php
if(isset($_POST['submit'])){
$Name = "Username:".$_POST['username'];
$gender = "Gender:".$_POST['gender'];
$file=fopen("saved.txt", "a");
fwrite($file, $Name);
fwrite($file, $Pass);
fwrite($file,"*************************");
fclose($file);
}
?>
<html>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('.check').click(function() {
$('.check').not(this).prop('checked', false);
});
});
</script>
<form action = "post.php" method="POST">
<p>
<label>Login Name:</label><input type = "text" name = "username" />
<br>
<input type="checkbox" name="gender" class="check" value="male"> Male
<input type="checkbox" name="gender" class="check" value="female"> Female
<input type="checkbox" name="gender" class="check" value="other"> Other
<br/>
<br/>
</p>
<input type = "submit" name="submit_btn" id = "submit" value = "submit"/>
<input type = "reset" id = "reset" value = "reset"/>
</form>
</body>
</html>
我建議您了解有關 HTML forms的更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.