【发布时间】:2021-11-28 22:52:13
【问题描述】:
我在通过 VSCODE 提交表单数据时遇到问题。所以基本上我有一个在 vscode 上运行的 nodejs 程序,我的目标是将一些输入数据从该程序提交到一个在线表单。
- 在 vscode 中运行 program.js 文件
- 文件挑选出用户名字段
- 通过php提交到在线文件
这是将输入用户名数据写入 data.txt 的 HTML 文件和 PHP 文件
<!DOCTYPE html>
<html>
<BODY>
<form action = "submit.php" method="POST">
<p>
<input type = "text" name = "username" />
</p>
<input type = "submit" name="submit_btn" id = "submit" value = "Submit"/>
</form>
</BODY>
</html>
<?php
if(isset($_POST['submit_btn']))
{
$username = $_POST['username'];
$text = $username ."\n";
$fp = fopen('data.txt', 'a+');
if(fwrite($fp, $text)) {
echo 'saved';
}
fclose ($fp);
}
$lines = file("data.txt"); // Get the file as an array
$lines = array_unique($lines); // Merge all duplicate lines
// Save as a new file
$file = fopen("datacurated.txt", "w");
fwrite($file, implode("", $lines));
fclose($file);
?>
所以 html 文件并不是很重要,但我不太擅长编码我试图通过 vscode 发送一个发布数据请求但没有工作。 我想知道是否有可能摆脱 html 文件并保持 php 在线并让它写入所需的数据。我还需要 php 文件中的删除重复文本功能。 这可以在 vscode 中使用 AXIOS 吗?
【问题讨论】:
-
Node 是如何/从哪里进来的?
-
节点程序运行良好我想制作一个单独的node.js文件,将用户名数据写入php并提交
-
如果可能的话,去掉 html
-
我认为您需要对原始问题进行澄清。 1.program.js在哪里? 2. 从哪里挑出一个用户名字段? 3.“在线文件”是什么/在哪里? “通过php提交”是什么意思?
-
你有那个“在线表格”的网址吗?