Search code examples
phphtmlimageerror-handlingpchart

PHP-how to send data to another php-sql page and recive an chart image on the same page


PHP-how to send data to another php-sql page and recive an chart image on the same page

hi guys. i have an problem and i dont know how i could solve that. i have an mainpage, where i want to put some data in an input field, which would send the data to an other page to create the chart. ok. thats not the problem. it works fine, if i open the secound page. the chart img is created. but if i want to stay on the mainpage klicking the button and recive the img from the secound page, the img is empty and i dont know how to realize that.

here is an short code of the mainpage.php

echo "<form action='#' method='post' type='text'>";
echo "Abzufragendes Jahr [JJJJ]:";
echo '<input type="text" name="eingabe_1" value="">';
echo "<input type='submit' name='eingabe_2' value='DB Abfrage'/>";
echo "<input type='submit' name='ausgabe_statistik' value='Charts erstellen' 
formaction='#' formmethod='post'/></br></br></br></br>";
echo "</form>";

//Versuch das Bild zu erzeugen
if(isset($_POST['eingabe_1']) && isset($_POST['ausgabe_statistik'])) {
  echo "<img src='charts/charts_jahr.php'> </br>";
}

and the secound page consists

include("../../PHP/pChart2.1.4/class/pData.class.php"); 
include("../../PHP/pChart2.1.4/class/pDraw.class.php"); 
include("../../PHP/pChart2.1.4/class/pImage.class.php"); 

include("../../SQL/log-in.php"); 
mysql_select_db(MYSQL_DATENBANK) or die("Auswahl der Datenbank fehlgeschlagen");

for ($a = 1 ; $a <= 365 ; $a++) {
  $kalenderwoche[] = $a;
}
$var = $_POST['eingabe_11'];
$var_jahr = "j" . $var;

$Result = mysql_query("SELECT sum(gewicht) as gewicht_1 FROM $var_jahr group by datum",$db_link);
while($row = mysql_fetch_array($Result))
{
  $gewicht[] = $row["gewicht_1"];
  $fett[] = $row["fett"];
}
//chartpart  
$myData = new pData();
$myData->addPoints($gewicht,"Serie1");
..
.

i thought over another solution to save the temp var in he sql and get the value for $var_jahr out of them. but i think thats not the solution right?

br and many thx for an solution!


Solution

  • My solution:

        if ( isset($_POST['statistik_gewicht']) ) {
                $var22 = $_POST['eingabe_1'];
                mysql_query("update variablen set var1 = $var22 where id = 1");
                mysql_query("update variablen set var_gewicht = 1 where id = 1");
                echo "<div align='center'><img src='charts/charts_jahr.php'></div> </br>";
        }
    

    Not well, but it works! Write an tmp var over

    echo '<td colspan="3">Abzufragendes Jahr [JJJJ]';  echo '<input type="text"     name="eingabe_1" value="">';