Problème requête Update sql
comondo123
Messages postés
12
Statut
Membre
-
Utilisateur anonyme -
Utilisateur anonyme -
bonjour,j'ai modifie sur mes données mais il ne change pas il reste toujours la même données ou est le problème ?
<?php
if(isset($_GET['mod_prod'])){
$id_prod=$_GET['mod_prod'];
$prod=mysql_query("select * from formation where id='$id_prod'");
$res_prod=mysql_fetch_array($prod);
}
?>
<div class="form">
<form action="#" method="post" class="niceform" enctype="multipart/form-data">
<fieldset>
<dl>
<dt><label for="password">Titre:</label></dt>
<dd>
<input type="text" name="titre" id="" size="54" value="<?php if(isset($_GET['mod_prod'])) echo $res_prod['titre'];?>"/>
</dd>
</dl>
<dl>
<dl>
<dt><label for="password">Titre1:</label></dt>
<dd>
<input type="text" name="titre1" id="" size="54" value="<?php if(isset($_GET['mod_prod'])) echo $res_prod['titre1'];?>"/>
</dd>
</dl>
<dl>
<dt><label for="comments" >text:</label></dt>
<dd><textarea name="text" id="comments" rows="5" cols="36">
<?php
if(isset($_GET['mod_prod'])) echo $res_prod['text'];
?>
</textarea></dd>
</dl>
<dl>
<dt><label for="upload">Upload a File:</label></dt>
<dd><input type="file" name="image" id="upload" value="<?php if(isset($_GET['mod_prod'])) echo $res_prod['image'];?>" /></dd>
</dl>
<dl class="submit">
<input type="hidden" name="hide" id="submit" value="<?php echo $_GET['mod_prod'];?>" />
<input type="submit" name="valider" id="submit" value="Modifier" />
</dl>
</fieldset>
</form>
</div>
</div><!-- end of right content-->
</div> <!--end of center content -->
<?php
//fonction d'upload-----------------------------------------------------------------------------
function upl($tmp, $tpe, $nme){
$content_dir="../images/";
$tmp_file = $tmp;
if( !is_uploaded_file($tmp_file) )
{
exit("Le fichier est introuvable");
}
$type_file = $tpe;
if( !strstr($type_file, 'jpg') && !strstr($type_file, 'jpeg') && !strstr($type_file, 'bmp') && !strstr($type_file, 'gif')&& !strstr($type_file, 'png') )
{
exit("Le fichier n'est pas une image");
}
if( !move_uploaded_file($tmp_file, $content_dir . $nme))
{
exit("Impossible de copier le fichier dans $content_dir");
}
echo "<br/>Le fichier a bien été uploadé";
} //
//ajout-------------------------------------------------------------------------------------
if(isset($_POST['valider']))
{
$idp=$_POST['hide'];
$reqq="select * from formation where id=$idp LIMIT 1";
$prod=mysql_query($reqq);
$res_prod=mysql_fetch_array($prod);
$img=$res_prod['image'];
$titre=$_POST['titre'];
$titre1=$_POST['titre1'];
$des=$_POST['text'];
$f="image";
$name_file = $_FILES[$f]['name'];
$chemin= $name_file;
if($chemin!="")
{
$ftpe = $_FILES[$f]['type'];
$ftmp = $_FILES[$f]['tmp_name'];
upl($ftmp, $ftpe, $name_file);
}else
{
$chemin=$img;
}
$modi=mysql_query("UPDATE produit SET id=$id,titre= '$titre',titre1= '$titre1',text='$des',image='$chemin' WHERE id=$idp LIMIT 1
");
if($modi){
echo "<script>alert('Votre actualité a été bien modifiée');</script>";
echo'<script language="javascript">location="acceuil.php"</script>';
}
}
?>
<?php
if(isset($_GET['mod_prod'])){
$id_prod=$_GET['mod_prod'];
$prod=mysql_query("select * from formation where id='$id_prod'");
$res_prod=mysql_fetch_array($prod);
}
?>
<div class="form">
<form action="#" method="post" class="niceform" enctype="multipart/form-data">
<fieldset>
<dl>
<dt><label for="password">Titre:</label></dt>
<dd>
<input type="text" name="titre" id="" size="54" value="<?php if(isset($_GET['mod_prod'])) echo $res_prod['titre'];?>"/>
</dd>
</dl>
<dl>
<dl>
<dt><label for="password">Titre1:</label></dt>
<dd>
<input type="text" name="titre1" id="" size="54" value="<?php if(isset($_GET['mod_prod'])) echo $res_prod['titre1'];?>"/>
</dd>
</dl>
<dl>
<dt><label for="comments" >text:</label></dt>
<dd><textarea name="text" id="comments" rows="5" cols="36">
<?php
if(isset($_GET['mod_prod'])) echo $res_prod['text'];
?>
</textarea></dd>
</dl>
<dl>
<dt><label for="upload">Upload a File:</label></dt>
<dd><input type="file" name="image" id="upload" value="<?php if(isset($_GET['mod_prod'])) echo $res_prod['image'];?>" /></dd>
</dl>
<dl class="submit">
<input type="hidden" name="hide" id="submit" value="<?php echo $_GET['mod_prod'];?>" />
<input type="submit" name="valider" id="submit" value="Modifier" />
</dl>
</fieldset>
</form>
</div>
</div><!-- end of right content-->
</div> <!--end of center content -->
<?php
//fonction d'upload-----------------------------------------------------------------------------
function upl($tmp, $tpe, $nme){
$content_dir="../images/";
$tmp_file = $tmp;
if( !is_uploaded_file($tmp_file) )
{
exit("Le fichier est introuvable");
}
$type_file = $tpe;
if( !strstr($type_file, 'jpg') && !strstr($type_file, 'jpeg') && !strstr($type_file, 'bmp') && !strstr($type_file, 'gif')&& !strstr($type_file, 'png') )
{
exit("Le fichier n'est pas une image");
}
if( !move_uploaded_file($tmp_file, $content_dir . $nme))
{
exit("Impossible de copier le fichier dans $content_dir");
}
echo "<br/>Le fichier a bien été uploadé";
} //
//ajout-------------------------------------------------------------------------------------
if(isset($_POST['valider']))
{
$idp=$_POST['hide'];
$reqq="select * from formation where id=$idp LIMIT 1";
$prod=mysql_query($reqq);
$res_prod=mysql_fetch_array($prod);
$img=$res_prod['image'];
$titre=$_POST['titre'];
$titre1=$_POST['titre1'];
$des=$_POST['text'];
$f="image";
$name_file = $_FILES[$f]['name'];
$chemin= $name_file;
if($chemin!="")
{
$ftpe = $_FILES[$f]['type'];
$ftmp = $_FILES[$f]['tmp_name'];
upl($ftmp, $ftpe, $name_file);
}else
{
$chemin=$img;
}
$modi=mysql_query("UPDATE produit SET id=$id,titre= '$titre',titre1= '$titre1',text='$des',image='$chemin' WHERE id=$idp LIMIT 1
");
if($modi){
echo "<script>alert('Votre actualité a été bien modifiée');</script>";
echo'<script language="javascript">location="acceuil.php"</script>';
}
}
?>
A voir également:
- Problème requête Update sql
- Windows update bloqué - Guide
- Winget update - Guide
- Asus live update - Télécharger - Utilitaires
- Wsus offline update - Télécharger - Systèmes d'exploitation
- Nettoyage windows update - Guide
4 réponses
comme tu récupères $id_prod
dans la condition if(isset($_GET['mod_prod']
il faut que ton champ caché:
<input type="hidden" name="hide" id="submit" value="<?php echo $_GET['mod_prod'];?>" />
ai comme name mod_prod
et que tu fait ton update en testant isset($_POST['valider']
dans la condition if(isset($_GET['mod_prod']
il faut que ton champ caché:
<input type="hidden" name="hide" id="submit" value="<?php echo $_GET['mod_prod'];?>" />
ai comme name mod_prod
<input type="hidden" name="mod_prod" id="submit" value="<?php echo $_GET['mod_prod'];?>" />
et que tu fait ton update en testant isset($_POST['valider']