2016-07-23 3 views
0

Ich möchte meine SQL-Anweisung mit einem Eingabetextfeld aktualisieren und muss den Wert übergeben.Wie kann ich den Eingabewert von einer anderen PHP-Datei erhalten?

Ich habe eine index.php Datei und eine getDataC.php Datei. Ich muss einen Wert in das Textfeld im Index einfügen, um eine SQL-Anweisung in getDataC zu aktualisieren, um eine Funktion im Index damit zu verwenden. Wie kann ich den Wert des Indexfeldes an getDataC übergeben, um es wieder im Index zu verwenden?

mein Code hier von 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> 

Und hier der Code von 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; 
?> 

Nun wird die else-Anweisung von getDataC Sätze $k-'Germany' da scheint es, dass der Text des Eingabefeldes LandC wird nicht an getDataC übergeben.

+1

Btw, Ihr Code ist wahrscheinlich anfällig für SQL-Injektion: http://StackOverflow.com/Questions/60174/How-CanI-I-Prevent-SQL-Injection-in-PHP – chrki

+0

@YeuSeChia diese funktionieren nicht, weil ich arbeite hier mit google charts und muss auf index.php bleiben diese lösungen alle schicken mich auf getDataC –

Antwort

0

Ihr Formular-Tag mit diesem Tag ändern <form action="HERE PUT THE PLACE OF TH FILE getDATAC.php" method="GET">

0
<form> 

werden sollten:

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

die Aktion den richtigen Pfad der Datei zu halten.

0

Ihre HTML mit Change (Formular Aktion ändern, wenn Ihre Datei getDataC.php an einem anderen Ort ist):

<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> 

Ihre getDataC.php Datei mit Änderung:

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

ein PHP erstellen Datei, wo Sie Ihre Daten senden möchten. Und setzen Sie den gleichen Namen in Aktion.