Page 1 sur 1

Erreur UPDATE mysql

Posté : 10 déc. 2013, 13:56
par acym
Bonjour,
Mon code pour modifier une base de donnée, affiche une erreur à la ligne
WHERE id='$id' ";
voici le code
<?php


$dossier =$_POST['nom_dossier'];
$type_societe =$_POST['type_societe'];
$collaborateur =$_POST['collaborateur'];
$date_cloture =$_POST['date_cloture'];
$type_mission =$_POST['type_mission'];
$tache =$_POST['tache'];
$periodicite =$_POST['periodicite'];
$date_echeance =$_POST['date_echeance'];
$quantite =$_POST['quantite'];
$avancement =$_POST['avancement'];
$commentaire =$_POST['commentaire'];

 
   
    // on écrit la requête sql
    $sql = "UPDATE excel SET nom_dossier='$dossier',
                             type_societe='$type_societe',
                             collaborateur='$collaborateur',
                             date_cloture='$date_cloture',
                             type_mission='$type_mission',
                             tache='$tache',
                             periodicite='$periodicite',
                             date_echeance='$date_echeance',
                             quantite='$quantite',
                             avancement='$avancement',
                             commentaire='$commentaire'
                   
                    WHERE id='.$id' ";
                
    
    // on insère les informations du formulaire dans la table
    mysql_query($sql) or die('Erreur SQL !'.$sql.'<br>'.mysql_error());
        mysql_close();  // on ferme la connexion

    // on affiche le résultat 
    echo '<strong><center><h1>Le dossier a été modifié.</h1></center></strong>';

?> 
C'est quoi mon erreur?

le code afficher
<?php
//On verifie que le nom_dossier est defini
if(isset($_GET['id']))
{
	$id = intval($_GET['id']);
	//On verifie que le nom_dossier existe
	$dn = mysql_query('select nom_dossier, type_societe, collaborateur, date_cloture, type_mission,
						tache, periodicite, date_echeance, quantite, avancement, commentaire from excel where id="'.$id.'"');
	//On affiche les donnees de lutilisateur
	$dnn = mysql_fetch_array($dn);

?>
	<center><h2> MODIFIER LE DOSSIER &nbsp;&nbsp;
					<?php echo htmlentities($dnn['nom_dossier'], ENT_QUOTES, 'UTF-8'); ?>
			 </h2>
     <form method="post" action="modifier_client.php" enctype="multipart/form-data">
    <table>
    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
      </tr>
        <tr>
            <td>Nom Dossier</td>
            <td>
            <input name="nom_dossier" type="text" value="<?php echo htmlentities($dnn['nom_dossier'], ENT_QUOTES, 'UTF-8'); ?>" />
            </td>
            <td>&nbsp;</td>          
            <td>Type de Société</td>
            <td>
            	<input name="type_societe" type="text" value="<?php echo htmlentities($dnn['type_societe'], ENT_QUOTES, 'UTF-8'); ?>" />
            </td>
            <td>&nbsp;</td>          
            <td>Collaborateur *</td>
            <td> 
           	<input name="collaborateur" type="text" value="<?php echo htmlentities($dnn['collaborateur'], ENT_QUOTES, 'UTF-8'); ?>"/>
            </td>
            <td>&nbsp;</td>           
            <td>Date de cloture</td>
            <td>
            	<input name="date_cloture" type="text" value="<?php echo htmlentities($dnn['date_cloture'], ENT_QUOTES, 'UTF-8'); ?>" />
            </td>
        </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                <tr>
                    <td>Type de mission</td>
            <td>
            	<input name="type_mission" type="text" value="<?php echo htmlentities($dnn['type_mission'], ENT_QUOTES, 'UTF-8'); ?>" />
            </td>
                        <td>&nbsp;</td>
                   
                    <td>Tâche</td>
            <td>
            	<input name="tache" type="text" value="<?php echo htmlentities($dnn['tache'], ENT_QUOTES, 'UTF-8'); ?>" />
            </td>
                    <td>&nbsp;</td>     
                    <td>Périodicité</td>
            <td>
            	<input name="periodicite" type="text" value="<?php echo htmlentities($dnn['periodicite'], ENT_QUOTES, 'UTF-8'); ?>" />
            </td>
                     <td>&nbsp;</td>            
                    <td>Date d'échéance</td>
            <td>
            	<input name="date_echeance" type="text" value="<?php echo htmlentities($dnn['date_echeance'], ENT_QUOTES, 'UTF-8'); ?>" />
            </td>
                </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>Quantité</td>
            <td>
            	<input name="quantite" type="text" value="<?php echo htmlentities($dnn['quantite'], ENT_QUOTES, 'UTF-8'); ?>" />
            </td>
                        <td>&nbsp;</td>
                        <td>Avancement</td>
            <td>
            	<input name="avancement" type="text" value="<?php echo htmlentities($dnn['avancement'], ENT_QUOTES, 'UTF-8'); ?>" />
            </td>
                        <td>&nbsp;</td>
                        <td>Commentaire</td>
                        <td><textarea name="commentaire" rows="3" cols="21">
                            <?php echo htmlspecialchars($dnn['commentaire'], ENT_QUOTES, 'UTF-8'); ?>
                            </textarea>
                        </td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
    </table> 
    <center><input type="submit" name="modifier" value="MODIFIER"/></center>
</form>
   </center>

<?php
	}

	else
	{
		echo 'Ce nom de dossier n\'existe pas.';
	}
?>
Merci

Re: Erreur UPDATE mysql

Posté : 10 déc. 2013, 15:31
par Arshes
Bonjour, il faudrais que tu me dise l'erreur qui t'es afficher.

Un colseil, passe à PDO car les fonctions mysql() sont voué à disparaître lors des futur versions de PHP.

Re: Erreur UPDATE mysql

Posté : 10 déc. 2013, 16:02
par acym
Bonjour Arshes,
Ok pour PDO je vais voir ce que c'est et l'apprendre.

Voici l'erreur

Code : Tout sélectionner

Parse error: syntax error, unexpected '" ' "' (T_CONSTANT_ENCAPSED_STRING) in C:\wamp\www\Thea\Excel\modifier_client.php on line 51
ET le fichier qui va avec , car entre temps j'ai changé des codes
<?php
include('../config.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>scoreboard</title>
<link href="Css/style.css" type="text/css" rel="stylesheet"/>
<link href="Css/menuPage.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<div id="global">
	<div id="headerMenu">
		<div id="logo">
			<img src="../images/logo.jpg" width="100" height="56">
			<?php include_once'menuPage.php';?>
		</div><!-- end div logo-->
	</div><!-- end headerMenu -->
 	<div id="principale">

<?php


$dossier =$_POST['nom_dossier'];
$type_societe =$_POST['type_societe'];
$collaborateur =$_POST['collaborateur'];
$date_cloture =$_POST['date_cloture'];
$type_mission =$_POST['type_mission'];
$tache =$_POST['tache'];
$periodicite =$_POST['periodicite'];
$date_echeance =$_POST['date_echeance'];
$quantite =$_POST['quantite'];
$avancement =$_POST['avancement'];
$commentaire =$_POST['commentaire'];

 
   
    // on écrit la requête sql
    $sql = "UPDATE excel SET type_societe='$type_societe',
                             collaborateur='$collaborateur',
                             date_cloture='$date_cloture',
                             type_mission='$type_mission',
                             tache='$tache',
                             periodicite='$periodicite',
                             date_echeance='$date_echeance',
                             quantite='$quantite',
                             avancement='$avancement',
                             commentaire='$commentaire'

            WHERE id="'.$dossier'" ";
                
    
    // on insère les informations du formulaire dans la table
    mysql_query($sql) or die('Erreur SQL !'.$sql.'<br>'.mysql_error());
        mysql_close();  // on ferme la connexion

    // on affiche le résultat 
    echo '<strong><center><h1>Le dossier a été modifié.</h1></center></strong>';

?> 
    
 	<!-- fin du texte -->
 	
 	</div><!-- end div pricipale-->

</div><!-- end div global-->
</body>
</html>

Merci


Re: Erreur UPDATE mysql

Posté : 10 déc. 2013, 16:23
par sirakawa
WHERE id="'.$dossier'" "; me semble étrange
un
print "<br /$sql"; die(); (si $sql est le nom de la variable contenant la requête)
et un test du résultat dans phpmyadmin ou semblable serait éclairant
On peut passer à mysqli qui impose peu de changements

Re: Erreur UPDATE mysql

Posté : 10 déc. 2013, 16:41
par acym
Bonjour sirakawa,

en fait c'est moi qui ais mis ce code, car je voudrais modifier des données , par rapport à l'id qui lui est en auto_increment.
Mais rien ne dit que c'est correct.

Merci

Re: Erreur UPDATE mysql

Posté : 10 déc. 2013, 16:49
par Arshes
Tu as mal concaténer ta requête. Je te met le code que j'ai rectifier et qui devrait marcher :)
<?php
include('../config.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>scoreboard</title>
<link href="Css/style.css" type="text/css" rel="stylesheet"/>
<link href="Css/menuPage.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<div id="global">
        <div id="headerMenu">
                <div id="logo">
                        <img src="../images/logo.jpg" width="100" height="56">
                        <?php include_once'menuPage.php';?>
                </div><!-- end div logo-->
        </div><!-- end headerMenu -->
        <div id="principale">

<?php


$dossier =$_POST['nom_dossier'];
$type_societe =$_POST['type_societe'];
$collaborateur =$_POST['collaborateur'];
$date_cloture =$_POST['date_cloture'];
$type_mission =$_POST['type_mission'];
$tache =$_POST['tache'];
$periodicite =$_POST['periodicite'];
$date_echeance =$_POST['date_echeance'];
$quantite =$_POST['quantite'];
$avancement =$_POST['avancement'];
$commentaire =$_POST['commentaire'];

 
   
    // on écrit la requête sql
    $sql = 'UPDATE excel SET type_societe='.$type_societe.',
                             collaborateur='.$collaborateur.',
                             date_cloture='.$date_cloture.',
                             type_mission='.$type_mission.',
                             tache='.$tache.',
                             periodicite='.$periodicite.',
                             date_echeance='.$date_echeance.',
                             quantite='.$quantite.',
                             avancement='.$avancement.',
                             commentaire='.$commentaire.'

            WHERE id='.$dossier;
                
    
    // on insère les informations du formulaire dans la table
    mysql_query($sql) or die('Erreur SQL !'.$sql.'<br>'.mysql_error());
        mysql_close();  // on ferme la connexion

    // on affiche le résultat 
    echo '<strong><center><h1>Le dossier a été modifié.</h1></center></strong>';

?> 
    
        <!-- fin du texte -->
        
        </div><!-- end div pricipale-->

</div><!-- end div global-->
</body>
</html>
 

Re: Erreur UPDATE mysql

Posté : 10 déc. 2013, 17:50
par acym
Bonjour Arshes,
super , en fin de compte je me plantais aussi avec les ( ' ).
Maintenant c'est au niveau de ( tache et périodicité ) car à la base ce sont des list
en select.
donc en les modifiant à la main cela ne fonctionne pas.
On peut corriger le soucis, ou tu préfères que j'ouvre une autre sujet.

Merci pour ton aide

Re: Erreur UPDATE mysql

Posté : 10 déc. 2013, 20:10
par Arshes
J'ai pas compris ton problème. $tache et $periodicite viennent d'un select ? Alors la valeur retourné est celle contenu dans le value="" :wink:

Re: Erreur UPDATE mysql

Posté : 11 déc. 2013, 15:11
par acym
Bonjour Arshes,
oui tout à fait, mais sur la page mofidier il n'y a pas le select.
Donc si l'utilisateur ne l'a pas rempli au début , quand il appelle la page modifier le select n'apparait pas.
Alors comment mettre le select sur cette page?
Je suis un peu beaucoup bloqué.

Merci