Formulaire entree : testentree.php
Formulaire sortie : testresult.php
<b>testentree.php : </b>
----------------------------
<HTML>
<HEAD>
<TITLE> Entree requete MySQL sous PHP </TITLE>
<META http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</HEAD>
<BODY>
<!-- testentree.php -->
<?php
$serveur="localhost";
$login="pgil";
$pass="aip";
?>
<FORM ACTION= "testresult.php" METHOD=POST>
CHOISIR LA BASE POUR LA REQUETE SQL :
<BR><BR>
<SELECT NAME="database" SIZE=1 >
<?php
echo ("boucle test entree");
mysql_connect($serveur,$login,$pass);
$db_table = mysql_list_dbs();
for ($i = 0; $i < mysql_num_rows($db_table);$i++)
{
echo ("<OPTION>" . mysql_tablename($db_table,$i));
}
?>
</SELECT>
<BR><HR>
ENTRER LA REQUETE A EXECUTER :
<BR><BR>
<TEXTAREA NAME="req" COLS=50 ROWS=10> </TEXTAREA>
<BR><BR>
<INPUT TYPE=SUBMIT VALUE="LANCER LA REQUETE" NAME="param">
</FORM>
</BODY>
</HTML>
---
<b>testresult.php : </b>
----------------------------
<HTML>
<HEAD>
<TITLE> Resultat de Entree requete MySQL sous PHP </TITLE>
<META http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</HEAD>
<BODY>
<!-- testresult.php -->
<?php
$serveur="localhost";
$login="pgil";
$pass="aip";
// Recuperer parametres passes par Action = POST
$recup = $_POST["param"];
if (!empty($recup)) {
echo ($recup);
$database = trim($_POST["database"]);
$req = trim($_POST["req"]);
echo ("Database = " . $database);
echo ("Requete = " . $req);
}
echo (" TEST AFF. TestResult 1");
echo ("<BR><BR>");
echo (" TEST AFF. TestResult 2");
mysql_connect($serveur,$login,$pass);
echo ("Database = " . $database);
mysql_select_db($database);
echo ("<BR><BR>");
echo (" TEST AFF. TestResult 3");
echo ("Requete = " . $req);
$result = mysql_query($req);
echo ("<BR><BR>");
echo (" TEST AFF. TestResult 4");
?>
<HR><BR>
<FORM ACTION= "testentree.php" METHOD=POST>
<INPUT TYPE=SUBMIT VALUE="NOUVELLE REQUETE">
</FORM>
</BODY>
</HTML>
---------
<b>Environnement travail : </b>
--------------------------------------
Register_Globals = On
Utilisation methode POST
2 parametres passes database et req via variable param.
Tester via php -q fichier php
<b>Questions : </b>
------------------------
Undefined index sur $_POST["variable] , surprenant !!!
Variables database et req non definis dans testresult !!!
Merci d'avance pour reponses.
Partager