简体   繁体   English

如何从另一个PHP文件获取输入值?

[英]How can I get the input value, from another PHP file?

I want to update my SQL statement with an input text field and need to pass the value. 我想用输入文本字段更新SQL语句,并需要传递值。

I have an index.php file and a getDataC.php file. 我有一个index.php文件和一个getDataC.php文件。 I need to insert a value in the text field in index to update a SQL statement in getDataC to use a function in index with it. 我需要在索引的文本字段中插入一个值,以更新getDataC的SQL语句以在索引中使用函数。 How can I pass the value of the index field to getDataC to use it in index again? 如何将index字段的值传递给getDataC以再次在index中使用它?

Here my code, from index.php : 这是我的代码,来自index.php

<body>
<h1 align="center">BigData - Gruppe 2</h1>
</br>
<table width="100%" align="center">
    <tr>
        <td width="25%" align="center">
            <h2>Bitte w&auml;hlen Sie eine Abfrage aus!</h2>
        </td>
        <td width="75%" align="center">
            <h2>Grafische Darstellung</h2>
        </td>
    </tr>
    <tr>
        <td width="40%">
            <hr>
            <h3 align="center">Abfragen:</h3> </br>
            <div>
                Einfluss von Bildung auf Fertilitätsrate (Japan)
                <button type="submit" id="actionA">Anzeigen</button>
            </div> </br>
            <div>
                Einfluss von Internet auf Fertilitätsraten (Japan)
                <button type="submit" id="actionB">Anzeigen</button>
            </div> </br>
            <div>
                Einfluss von Internet und Bildung auf die Anzahl der Frauen in
                Wirtschaft/Politik </br>
                <form > <label for="LandC">Wähle ein Land: <input type=text id="LandC" name="LandC"> </label></form>

                <button type="submit" id="actionC">Anzeigen</button>
            </div> </br>

And, here the code from getDataC.php : 并且,这是来自getDataC.php的代码:

<?php
$con = mysqli_connect('localhost','root','','bigdata');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}

if( isset($_GET['submit']) )
{
//be sure to validate and clean your variables
$landC = htmlentities($_GET['LandC']);

}
if( isset($landC) ) {
 $k = $landC;
}
else $k='Germany';


$qry = "SELECT  * FROM facts WHERE facts.Country = '".  $k ."' AND Frauen_Fuehrungspositionen_Prozent IS NOT NULL";

$result = mysqli_query($con,$qry);

mysqli_close($con);

$table = array();
//Es´rstelt die Spaöten der Tabelle
$table['cols'] = array(
//Labels for the chart, these represent the column titles
array('id' => '', 'label' => 'Land', 'type' => 'string'),
    array('id' => '', 'label' => 'Jahr', 'type' => 'number'),

array('id' => '', 'label' => 'Staatsausgaben GDP per capita in Dollar', 'type' => 'number'),
array('id' => '', 'label' => 'Internetzugang in Prozent', 'type' => 'number'),

array('id' => '', 'label' => 'Frauen Fuehrungspositionen in Prozent', 'type' => 'number')

); 

$rows = array();
foreach($result as $row){
$temp = array();

//Values / Füllt die Spalten in der hier angegebenen Reihenfolge mit Zahlen
$temp[] = array('v' => (string) $row['Country']);
    $temp[] = array('v' => (int) $row['Year']); 

$temp[] = array('v' => (double) $row['Staatsausgaben_GDP_per_capita_in_Dollar']); 
    $temp[] = array('v' => (double) $row['Internetzugang_in_Prozent']); 

$temp[] = array('v' => (double) $row['Frauen_Fuehrungspositionen_Prozent']);
$rows[] = array('c' => $temp);

}   
$result->free();

$table['rows'] = $rows;

$jsonTable = json_encode($table, true);
echo $jsonTable;
?>

Now, the else statement of getDataC sets $k to 'Germany' since it seems that the text of the input field LandC doesn't get passed to getDataC . 现在, getDataC的else语句将$k设置$k 'Germany'因为似乎输入字段LandC的文本没有传递给getDataC

使用此标签更改您的表单标签<form action="HERE PUT THE PLACE OF TH FILE getDATAC.php" method="GET">在此<form action="HERE PUT THE PLACE OF TH FILE getDATAC.php" method="GET">

<form>

Should be: 应该:

<form action="getDataC.php" method="GET">

Keeping the action the correct path of the file. 保持操作正确的文件路径。

Your HTML with Change (change your form action if your file getDataC.php is at another location ) : 带有Change的HTML(如果文件getDataC.php位于另一个位置,则更改表单操作):

<body>
<h1 align="center">BigData - Gruppe 2</h1>
</br>
<table width="100%" align="center">
    <tr>
        <td width="25%" align="center">
            <h2>Bitte w&auml;hlen Sie eine Abfrage aus!</h2>
        </td>
        <td width="75%" align="center">
            <h2>Grafische Darstellung</h2>
        </td>
    </tr>
    <tr>
        <td width="40%">
            <hr>
            <h3 align="center">Abfragen:</h3> </br>
            <div>
                Einfluss von Bildung auf Fertilitätsrate (Japan)
                <button type="submit" id="actionA">Anzeigen</button>
            </div> </br>
            <div>
                Einfluss von Internet auf Fertilitätsraten (Japan)
                <button type="submit" id="actionB">Anzeigen</button>
            </div> </br>
            <div>
                Einfluss von Internet und Bildung auf die Anzahl der Frauen in
                Wirtschaft/Politik </br>
                <form action="getDataC.php">
                <label for="LandC">Wähle ein Land: <input type=text id="LandC" name="LandC"> </label>
                <button type="submit" id="actionC">Anzeigen</button>
                </form>
            </div> </br>

Your getDataC.php file with change : 您的带有更改的getDataC.php文件:

<?php
if(isset($_GET['LandC']) ){
//be sure to validate and clean your variables
$landC = htmlentities($_GET['LandC']);

}
if(isset($landC) ) {
 $k = $landC;
}
else $k='Germany';
$qry = "SELECT  * FROM facts WHERE facts.Country = '".  $k ."' AND Frauen_Fuehrungspositionen_Prozent IS NOT NULL";

$result = mysqli_query($con,$qry);

mysqli_close($con);

$table = array();
//Es´rstelt die Spaöten der Tabelle
$table['cols'] = array(
//Labels for the chart, these represent the column titles
array('id' => '', 'label' => 'Land', 'type' => 'string'),
    array('id' => '', 'label' => 'Jahr', 'type' => 'number'),

array('id' => '', 'label' => 'Staatsausgaben GDP per capita in Dollar', 'type' => 'number'),
array('id' => '', 'label' => 'Internetzugang in Prozent', 'type' => 'number'),

array('id' => '', 'label' => 'Frauen Fuehrungspositionen in Prozent', 'type' => 'number')

); 

$rows = array();
foreach($result as $row){
$temp = array();

//Values / Füllt die Spalten in der hier angegebenen Reihenfolge mit Zahlen
$temp[] = array('v' => (string) $row['Country']);
    $temp[] = array('v' => (int) $row['Year']); 

$temp[] = array('v' => (double) $row['Staatsausgaben_GDP_per_capita_in_Dollar']); 
    $temp[] = array('v' => (double) $row['Internetzugang_in_Prozent']); 

$temp[] = array('v' => (double) $row['Frauen_Fuehrungspositionen_Prozent']);
$rows[] = array('c' => $temp);

}   
$result->free();

$table['rows'] = $rows;

$jsonTable = json_encode($table, true);
echo $jsonTable;
?>

在要发送数据的位置创建一个php文件,并使用相同的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从自动完成中获得单击的输入单选值以将表单发送到 php 文件 - How can I get clicked input radio value from autocomplete to send in form to php file 如何从输入中获取价值并将其用于PHP查询中? - How can I get value from input and use it in query in PHP? 如何从另一个文件获取变量的值到函数php中? - How can I get the value of a variable from another file into the function php? 我如何从另一个PHP文件获取数据库详细信息? - how can i get the database details from another php file? PHP - 如何从隐藏输入类型和$ _POST到另一个PHP获取名称? - PHP - How can I get the name from input type hidden and $_POST to another php? (PHP)如何使输入隐藏数据从输入框中获取价值 - (PHP) How can I make input hidden data to get value from input box 如何从另一个PHP文件获取PHP变量值? - How to get a PHP variable value from another PHP file? 如何在没有表单标签的情况下将输入标签值从 HTML 文件发送到 PHP 文件? - How can I send input tag value from HTML file to PHP file without form tag? PHP和JSON:如何从另一个值等于xyz的位置获取值? - PHP & JSON: How can I get a value from where another value equals xyz? 如何将输入从PHP脚本传递到另一个脚本? - How can I pass the input from a PHP script to another script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM