我有一个网页,其中包含一个输入,其名称为code_client
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<form action="getLatLon.php" method="POST">
<fieldset>
code_client: <input id="code_client" name="code_client" type="text"> <br><br>
<br>
<input type="submit" value="Voir" name="Chercher">
</fieldset>
</form>
</body>
</html>
网页网页的图像:
当我输入值时,我将其发送(POST)到getLatLong.php文件中,并因此显示客户端的信息(code_client的所有者)
getLatLon.php
<?php
$DB_Server = "localhost"; //MySQL Server
$DB_Username = "root"; //MySQL Username
$DB_Password = "123456"; //MySQL Password
$DB_DBName = "db_abc"; //MySQL Database Name
$DB_TBLName = "location"; //MySQL Table Name
$code_client=$_POST['code_client'];
$objConnect = @mysqli_connect($DB_Server, $DB_Username, $DB_Password);
$objDB = @mysqli_select_db($objConnect, $DB_DBName);
$strSQL = "SELECT * FROM `location` WHERE CodeClient='".$code_client."' ";
$objQuery = @mysqli_query($objConnect, $strSQL) or die("Couldn't execute query:<br>" . mysqli_error(). "<br>" . mysqli_errno());
$arrRows = array();
$arryItem = array();
while($arr = mysqli_fetch_array($objQuery)) {
$arryItem["Id"] = $arr["Id"];
$arryItem["Latitude"] = $arr["Latitude"];
$arryItem["Longitude"] = $arr["Longitude"];
$arryItem["CodeClient"] = $arr["CodeClient"];
$arrRows[] = $arryItem;
}
$DATA = $arrRows;
echo json_encode($arrRows);
?>
结果图片
我尝试将表单的结果发送到另一个php文件
testExportvr.php
<?php
include 'getLatLon.php';
echo json_encode($DATA);
?>
我尝试将模板的结果发送到另一个php文件,但是直到现在我还是做不到,它显示的结果与正确的结果不同
有人知道我在做什么错吗?我需要表格将数据提交到文件中,同时结果将显示在另一个文件中
答案 0 :(得分:1)
您说的是要将结果保存到文件中并在另一页中显示结果。 为此,您不需要名为“ testExportvr.php”的第三个文件。 您必须使用php文件处理(我假设您要将其保存为文本文件)
您只需要在“ getLatLon.php”中进行更改 像这样
<?php
$DB_Server = "localhost"; //MySQL Server
$DB_Username = "root"; //MySQL Username
$DB_Password = "123456"; //MySQL Password
$DB_DBName = "db_abc"; //MySQL Database Name
$DB_TBLName = "location"; //MySQL Table Name
$code_client=$_POST['code_client'];
$objConnect = @mysqli_connect($DB_Server, $DB_Username, $DB_Password);
$objDB = @mysqli_select_db($objConnect, $DB_DBName);
$strSQL = "SELECT * FROM `location` WHERE CodeClient='".$code_client."' ";
$objQuery = @mysqli_query($objConnect, $strSQL) or die("Couldn't execute query:<br>" . mysqli_error(). "<br>" . mysqli_errno());
$arrRows = array();
$arryItem = array();
while($arr = mysqli_fetch_array($objQuery)) {
$arryItem["Id"] = $arr["Id"];
$arryItem["Latitude"] = $arr["Latitude"];
$arryItem["Longitude"] = $arr["Longitude"];
$arryItem["CodeClient"] = $arr["CodeClient"];
$arrRows[] = $arryItem;
}
$DATA = $arrRows;
$file = fopen("data.txt", "w") or die("Unable to open file!");
fwrite($file, json_encode($DATA));//in case if you want to save text as json format
fclose($file);
echo json_encode($arrRows);
?>