我创建了一个Web应用程序,可以将表单提交到数据库,然后在服务器中创建一个文本文件。提交表单(update.php)后,它将重定向到另一个html文件,但我很困惑它将如何自动运行另一个php文件来创建一个文本文件。
这是我的update.php
<html><head>
<meta http-equiv="refresh" content="2;url=index.php">
<body>
<?php
include 'connectdb.php';
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$name = $_POST["name"];
$lastname = $_POST["lastname"];
//echo $name," ",$lastname;
$insertsql = "UPDATE user SET name ='$name', lastname='$lastname' ";
if($conn->query($insertsql) === TRUE){
echo "update ok";
}
else{
echo "Error :" . $insertsql . "<br>" . $conn->error;
}
$conn->close();
exec('php build_conf.php');
?>
</body></head></html>
我尝试过exec但是没有用。它可以完美地更新到数据库。但它无法运行build_conf.php文件。 当我运行命令时:
php build_conf.php
它也很完美。
这是build_con.php
<?php
include 'fetch_data.php';
error_reporting(E_ALL);
$file_name = 'poll.conf';
$file_name_path = '/var/www/html/home/test_connect/'.$file_name;
$file_conn = fopen("$file_name_path","w") or die("Unable to open");
$DocumentRoot = "My name is ".$name."\n";
fwrite($file_conn, $DocumentRoot);
$Hill = "My lastname is ".$lastname."\n";
fwrite($file_conn, $Hill);
fclose($file_conn);
&GT;
这些都是关于测试代码的。 如果你可以帮助我,那将是非常好的:)
答案 0 :(得分:0)
只需包含文件:
include_once 'build_conf.php';
此外,您可以将其封装在一个功能中:
function createFile(){}
include 'fetch_data.php';
error_reporting(E_ALL);
$file_name = 'poll.conf';
$file_name_path = '/var/www/html/home/test_connect/'.$file_name;
$file_conn = fopen("$file_name_path","w") or die("Unable to open");
$DocumentRoot = "My name is ".$name."\n";
fwrite($file_conn, $DocumentRoot);
$Hill = "My lastname is ".$lastname."\n";
fwrite($file_conn, $Hill);
fclose($file_conn);
}
从update.php调用它:
include_once 'build_conf.php';
createFile();