1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| <?php
$host = "hostname";
$user = "user";
$password = "password";
$db_name = "ma_base";
@mysql_connect($host,$user,$password) or die ("echec de connection au serveur");
@mysql_select_db($db_name) or die ("echec de selection de la base");
//extraction des variables
extract($_POST);
//modification d'un tuple
if(isset($appli_modif)){
$sql = "UPDATE ma_table
SET nom_champ = '".$nom_champ."',
champ_1 = '".$champ_1."',
champ_2 = '".$champ_2."'
WHERE id = $appli_modif";
$req = mysql_query($sql) or die ("echec lors de la modification dans la table : ".mysql_error());
unset($appli_modif);
}
//suppression d'un tuple
if(isset($delete)){
$sql = "DELETE
FROM ma_table
WHERE id=".$delete."";
$req = mysql_query($sql) or die ("echec lors de la suppression dans la table : ".mysql_error());
unset($delete);
}
//vidage de la table
if(isset($clear_table)){
$sql = "DELETE
FROM ma_table";
$req = mysql_query($sql) or die ("echec lors du vidage de la table : ".mysql_error());
unset($delete);
}
//ajout d'un tuple
if(isset($add)){
$sql = "INSERT INTO ma_table (nom_champ,champ_1,champ_2)
VALUE ('$nom_champ','$champ_1','$champ_2')";
$req = mysql_query($sql) or die ("echec lors de l'insertion dans la table : ".mysql_error());
}
//formulaire d'ajout
print("
<form action=\"$PHP_SELF\" method=\"post\">
nom du champ : <input type=\"text\" name=\"nom_champ\"/><br/>
valeur champ 1 : <input type=\"text\" name=\"champ_1\"/><br/>
valeur champ 1 : <input type=\"text\" name=\"champ_2\"/><br/>
<input type=\"hidden\" name=\"add\"/>
<input type=\"submit\" value=\"Ajouter\"/>
</form>");
//formulaire de vidage de la table
print("
<form action=\"$PHP_SELF\" method=\"post\">
<input type=\"hidden\" name=\"clear_table\"/>
<input type=\"submit\" value=\"Vider la table\"/>
</form>");
//affichage de la table ma_table
$sql = "SELECT *
FROM ma_table";
$req = @mysql_query ($sql) or die ("echec de listage de la table ma_table : ".mysql_error());
print("
<table border=\"1\">
<tr>
<th>Nom du champ</th>
<th>Variable A</th>
<th>Variable B</th>
<th>Total</th>
<th>Modifier</th>
<th>Supprimer</th>
</tr>");
while($row = mysql_fetch_assoc($req)){
if(isset($modif) && $modif == $row['id']){
print("
<tr>
<form action=\"$PHP_SELF\" method=\"post\">
<input type=\"hidden\" name=\"appli_modif\" value=\"".$row['id']."\"/>
<td><input type=\"text\" name=\"nom_champ\" value=\"".$row['nom_champ']."\"/></td>
<td><input type=\"text\" name=\"champ_1\" value=\"".$row['champ_1']."\"/></td>
<td><input type=\"text\" name=\"champ_2\" value=\"".$row['champ_2']."\"/></td>
<td/>
<td><input type=\"submit\" value=\"Valider\"></td>
<td/>
</form>
</tr>");
unset($modif);
}else{
print("
<tr>
<td>".$row['nom_champ']."</td>
<td>".$row['champ_1']."</td>
<td>".$row['champ_2']."</td>
<td>".($row['champ_1'] + $row['champ_2'])."</td>
<td><a href=\"$PHP_SELF?modif=".$row['id']."\">modifier</a></td>
<td><a href=\"$PHP_SELF?delete=".$row['id']."\">Supprimer</a></td>
</tr>");
}
}
print("
</table>");
?> |
Partager