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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
<?php
// Paramètres de connexion
$hostname_dbprotect = "localhost"; // nom ou ip de notre serveur
$database_dbprotect = "galerie_photos"; // nom de notre base de données
$username_dbprotect = "root";
$password_dbprotect = "";
$dbprotect = mysql_pconnect("localhost", "root", "") or trigger_error(mysql_error(),E_USER_ERROR);
?>
<?php
// ------ modifier une image--------
mysql_select_db($database_dbprotect, $dbprotect);
$query_modification = "SELECT * FROM photo ORDER BY titre_photo ASC"; // renvoi les données triées (ici par titre croissant)
$users = mysql_query($query_modification, $dbprotect) or die(mysql_error());
$row_users = mysql_fetch_assoc($users);
if(isset($_POST['modification'])){ // on vérifie la présence des variables de formulaire (si le formulaire a été envoyé)
// on passe toutes les variables $POST en variables
$id = $_POST['modification'];
$categorie = $_POST['categorie'];
$titre_photo = $_POST['titre_photo'];
$commentaire = $_POST['commentaire'];
$path_photo = $_POST['path_photo'];
$date_ajout = $_POST['date_ajout'];
if($_POST['categorie'] != "")
{
$modifier = 'UPDATE `photo` SET `categorie`= "'.$categorie.'" WHERE `id_photo`= "'.$id.'"';
//$modifier = "UPDATE photo set categorie='$categorie' WHERE id_photo='$id' ";
mysql_select_db($database_dbprotect, $dbprotect);
$result = mysql_query($modifier, $dbprotect) or die(mysql_error());
//header("Location:admin.php?modif=ok"); // redirection si modification réussie
}
if($_POST['titre_photo'] != "")
{
$modifier ='UPDATE `photo` SET `titre_photo`= "'.$titre_photo.'" WHERE `id_photo`= "'.$id.'"';
//$modifier = sprintf("UPDATE photo set titre_photo='$titre_photo' WHERE id_photo='$id' ");
mysql_select_db($database_dbprotect, $dbprotect);
$result = mysql_query($modifier, $dbprotect) or die(mysql_error());
//header("Location:admin.php?modif=ok"); // redirection si modification réussie
}
if($_POST['commentaire'] != "")
{
$modifier = 'UPDATE `photo` SET `commentaire`= "'.$commentaire.'" WHERE `id_photo`= "'.$id.'"';
//$modifier = "UPDATE photo set commentaire='$commentaire' WHERE id_photo='$id' ";
mysql_select_db($database_dbprotect, $dbprotect);
$result = mysql_query($modifier, $dbprotect) or die(mysql_error());
//header("Location:index.php?modif=ok"); // redirection si modification réussie
}
if($_POST['path_photo'] != "")
{
$modifier = 'UPDATE `photo` SET `path_photo`= "'.$path_photo.'" WHERE `id_photo`= "'.$id.'"';
//$modifier = "UPDATE photo set path_photo='$path_photo' WHERE id_photo='$id' ";
mysql_select_db($database_dbprotect, $dbprotect);
$result = mysql_query($modifier, $dbprotect) or die(mysql_error());
//header("Location:index.php?modif=ok"); // redirection si modification réussie
}
if($_POST['date_ajout'] != "")
{
//$modifier = "UPDATE photo set date_ajout='$date_ajout' WHERE id_photo='$id' ";
$modifier = 'UPDATE `photo` SET `date_ajout`= "'.$date_ajout.'" WHERE `id_photo`= "'.$id.'"';
mysql_select_db($database_dbprotect, $dbprotect);
$result = mysql_query($modifier, $dbprotect) or die(mysql_error());
//header("Location:index.php?modif=ok"); // redirection si modification réussie
}
}
?>
<html>
<head>
<title>Modifier une photo</title>
<script type="text/javascript" language="Javascript" >
<!--
function verification()
{
//verification de la catégorie
if(document.formulaire.categorie.value == "") {
alert("Veuillez entrer la catégorie");
document.formulaire.categorie.focus();
return false;
}
//verification du titre
if(document.formulaire.titre_photo.value == "") {
alert("Veuillez entrer un titre pour la photo");
document.formulaire.titre_photo.focus();
return false;
}
//verification de date
if(document.formulaire.date_ajout.value == "") {
alert("Veuillez entrer la date d'ajout");
document.formulaire.date_ajout.focus();
return false;
}
var d=document.formulaire.date_ajout.value; //champ de la date
var amin=2007; // année mini
var amax=2020; // année maxi
var separateur="-"; // separateur entre jour/mois/annee
var j=(d.substring(8));
var m=(d.substring(5,7));
var a=(d.substring(0,4));
var ok=1;
if ( ((isNaN(a))||(a<amin)||(a>amax)) && (ok==1) ) {
alert("L'année n'est pas correcte."); ok=0;
}
if ( ((isNaN(m))||(m<1)||(m>12)) && (ok==1) ) {
alert("Le mois n'est pas correct."); ok=0;
}
if ( ((isNaN(j))||(j<1)||(j>31)) && (ok==1) ) {
alert("Le jour n'est pas correct."); ok=0;
}
if ( ((d.substring(4,5)!=separateur)||(d.substring(7,8)!=separateur))
&& (ok==1) ) {
alert("Les séparateurs doivent être des "+separateur); ok=0;
}
}
//-->
</script>
<link href="styles.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="F79543">
<form action="" method="post" name="modif">
<p align="center"><strong><u>Modifier une photo</u></strong></p>
<p align="center">
<? if(isset($_GET['modif']) && ($_GET['modif'] == "ok")) { // Affiche l'erreur ?>
<span class="reussite">La modification a été faite avec succès !</span>
<? } ?>
</p>
<table width="500" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#eeeeee" class="tableaux">
<tr>
<td>Choisissez le titre de la photo que vous voulez modifier</td>
<td><div align="center">
<select name="titre_photo" STYLE="width:190">
<?php
do {
?>
<option value="<?php echo $row_users['id_photo']?>">
<?php echo $row_users['titre_photo']?>
</option>
<?php
} while ($row_users = mysql_fetch_assoc($users));
$rows = mysql_num_rows($users);
if($rows > 0) {
mysql_data_seek($users, 0);
$row_users = mysql_fetch_assoc($users);
}
?>
</select>
</div>
</td>
</tr>
<tr><td> Choisissez la catégorie de la photo</td>
<td>
<select name="categorie" id="categorie" STYLE="width:190">
<option> </option>
<option>Nature</option>
<option>BD-Mangas</option>
<option>Celebrites</option>
<option>Monde</option>
<option>Sport</option>
<option>Carte de voeux</option
</select>
</td>
</tr>
<tr><td>Entrez le commentaire de la photo</td>
<td><TEXTAREA name="commentaire" type="text" id="commentaire" COLS=20 ROWS=4 WRAP=virtual></TEXTAREA></td></tr>
<tr><td>Entrez la date d'ajout</td>
<td><input name="date_ajout" type="text" id="date_ajout"></td></tr>
<tr><td>Entrez le path de la photo<br> sous la forme:"./images/nom de l'image"</td>
<td><input type="text" name="path_photo" id="path_photo"></td></tr>
<tr><td height="50" colspan="2"><div align="center">
<input type="submit" name="Submit" value="Modifier la photo">
</div></td>
</tr>
<tr><td><font face="Comic Sans MS" size="2" color="#FF0000"><b>N'oubliez pas de placer l'image dans le répertoire images de votre espace de travail</b></td></tr>
</table>
</form>
<form action="" method="post" name="ajout">
<p align="center"><strong><u>Ajouter une photo</u></strong></p>
<table width="500" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#eeeeee" class="tableaux">
<tr>
<td height="50" colspan="2"><div align="center">
<a href="./ajouter.php">Faire l'ajout</a>
</div></td>
</tr>
</table>
</form>
<form action="" method="post" name="suppression">
<p align="center"><strong><u>Supprimer une photo</u></strong></p>
<table width="500" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#eeeeee" class="tableaux">
<tr>
<td height="50" colspan="2"><div align="center">
<a href="./supprimer.php">Faire la suppression</a>
</div></td>
</tr>
<tr><td><a href="index.php">retour à l'accueil </a></td> </tr>
</table>
</form>
</body>
</html> |
Partager