Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法从php脚本运行php脚本_Php_Apache - Fatal编程技术网

无法从php脚本运行php脚本

无法从php脚本运行php脚本,php,apache,Php,Apache,我制作了一个web应用程序,它可以将表单提交到数据库,然后在服务器中创建一个文本文件。当提交表单(update.php)后,它将重定向到另一个html文件,但我很困惑它如何自动运行另一个php文件来创建文本文件 这是我的update.php <html><head> <meta http-equiv="refresh" content="2;url=index.php"> <body> <?php include 'connectdb.ph

我制作了一个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>
它也能很好地工作

这是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);

这些都是关于测试代码的。 如果您能帮助我,那将是非常棒的:)

只需包含以下文件:

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();

你确定你在这条路上走对了吗?php web应用程序的常用方法是使用php脚本接受用户输入,如果需要进一步处理,则重定向到另一个url,该url当然由另一个php脚本处理。请尝试放置文件build_conf.php的绝对路径,并向我们显示
var_dump()
exec('php build_conf.php',$array,$code);变量转储($数组);var_dump($code)
include_once 'build_conf.php';
createFile();