【问题标题】:Form not posting what i need it to表格没有发布我需要的内容
【发布时间】:2021-01-06 09:17:27
【问题描述】:

我正在尝试使用 php, 我怎么不知道如何将输入数据从一个文件发布到另一个文件。

这是当前代码

<?php
if (isset($_POST['mysql'])) {
$my_file = 'test/core/config.php';
$handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file);
$data = '<?php
//connect to db
$host = "$host";  //i want the form value to be imported here
$user = "$user";
$port = "$port";
$pass = "$pass";
$db = "$db";

$sql = conn($host, $user, $port, $pass, $db);
 ?>';
fwrite($handle, $data);
}
?>

这里是html表单

<form class="form" action="testinstall.php" method="post">
<label for="host">Host</label>
<input type="text" name="host">
<label for="user">Username</label>
<input type="text" name="user">
<label for="port">Port</label>
<input type="text" name="port">
<label for="pass">Password</label>
<input type="text" name="pass">
<label for="db">Databace</label>
<input type="text" name="db">
<button type="submit" name="mysql">Submit</button>
</form>

【问题讨论】:

  • 当我这样做时,结果是
  • $host = "$host";
  • $user = "$user";
  • $port = "$port";

标签: php html mysql forms file


【解决方案1】:

试试这个:

$data = "<?php
//connect to db
$host = '$host';
$user = '$user';
$port = '$port';
$pass = '$pass';
$db = '$db';
   
$sql = conn($host, $user, $port, $pass, $db);
?>";

您应该使用 " outer 来打印变量的值。

【讨论】:

  • 我会试试的
  • 这样更好吗?
  • $host = $_POST['host'];
  • 看我全部熟悉php
  • 这是连接信息片段的更好方法。请尝试将您所有的问题放在一个评论中,最好让人们阅读并尝试帮助您。试试我的回答,如果它不能解决你做新的评论。好的,谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-15
  • 2015-08-04
  • 2021-03-02
  • 2015-11-12
  • 2010-10-14
  • 1970-01-01
相关资源
最近更新 更多