1

i have a web page that contains one input his name 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>

image of the page web :

enter image description here

when i enter the value i send it (POST) to a getLatLong.php file , and i display as a result the information of the client(the owner of the 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);

?>

the image of the result

enter image description here

i try to send the result of the forme to another php file

testExportvr.php

<?php

include 'getLatLon.php';

echo json_encode($DATA);

?>

i try to send the result of the forme to another php file , but until now i can't do it , it display some result different than the correct one

enter image description here

Does anyone know what I'm doing wrong? I need the form to submit the data to the file and in the same time the result will display in another file

8
  • How exactly are you sending the result to testExportvr.php? Anything less than another $_POST request will prevent that variable from being defined. Commented Jul 28, 2018 at 22:03
  • So you changed <form action="getLatLon.php" method="POST"> to <form action="testExportvr.php" method="POST"> or what exactly have you tried? Commented Jul 28, 2018 at 22:06
  • @Dan i tried to defin a globae variable in getLatLon.php i name it $DATA, and finaly i use it in testExportvr.php to display result , but it doesn't work . Commented Jul 28, 2018 at 22:11
  • @FrankerZ any ideas to make it work ??? Commented Jul 28, 2018 at 22:12
  • @akira, I'm asking about the way you pass the data to the file called testExportvr.php Commented Jul 28, 2018 at 22:19

1 Answer 1

1

You are saying that you want to save result into file and displaying the result in another page. For this u don't need third file named "testExportvr.php" you have to use php file handling(i am assuming you want to save it as text file)

you need to do changes only in "getLatLon.php" like this

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

?>
Sign up to request clarification or add additional context in comments.

4 Comments

thank you so much this is exactly what i am looking for
@akira you are welcome but it was hard to understand what you exacty want.
and you should be very clear about how you want to pass data
i will be more clearly next time . thank you so much for your advice

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.