Page 1 sur 1

pb d'update

Posté : 15 nov. 2005, 17:49
par philoult
Bonjour,

je voudrait faire une page de mise a jour de données.
J'arrive bien à récupérer mes données dans un page par contre lorsque j'envoi la modif j'ai un retour d'erreur.

Voici le code:
<?php
$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE coloc SET `PEC`=%s, finddp=%s, IDFACUSAGE=%s, acces_debit=%s, commentaire=%s WHERE societe=%s",
                       GetSQLValueString($POST['PEC'], "text"),
                       GetSQLValueString($POST['finddp'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['IDFACUSAGE'], "text"),
					   GetSQLValueString($HTTP_POST_VARS['acces_debit'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['commentaire'], "text"));

  mysql_select_db($base, $connexion);
  $Result1 = mysql_query($updateSQL, $connexion) or die(mysql_error());

  $updateGoTo = "confirmation-operation.htm";
  if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

mysql_select_db($base, $connexion);
$query_modifclient = "SELECT * FROM coloc WHERE societe='$societe'";
$modifclient = mysql_query($query_modifclient, $connexion) or die(mysql_error());
$row_modifclient = mysql_fetch_assoc($modifclient);
$totalRows_modifclient = mysql_num_rows($modifclient);

mysql_free_result($modifclient);
?><body>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  <p align="center"><strong><em><u><i><b><font color="#993333" size="6">Modification 
    des Infos Client</font></b></i></u></em></strong></p>
  <table width="600" height="988" align="center">
    <tr valign="baseline"> 
      <td width="100" align="right" nowrap><font size="-1" face="Arial, Helvetica, sans-serif">Date 
        PEC:</font></td>
      <td><font size="-1" face="Arial, Helvetica, sans-serif"> 
        <input type="text" name="date_PEC" value="<?php echo $row_modifclient['PEC']; ?>" size="32">
        </font></td>
          <td width="100" align="right" nowrap><font size="-1" face="Arial, Helvetica, sans-serif">Date 
        d instal:</font></td>
      <td><font size="-1" face="Arial, Helvetica, sans-serif"> 
        <input type="text" name="date_d_instal" value="<?php echo $row_modifclient['finddp']; ?>" size="32">
        </font></td>
    </tr>
    <tr valign="baseline"> 
      <td width="100" align="right" nowrap><font size="-1" face="Arial, Helvetica, sans-serif">IDFACUSAGE:</font></td>
      <td><font size="-1" face="Arial, Helvetica, sans-serif"> 
        <input type="text" name="IDFACUSAGE" value="<?php echo $row_modifclient['IDFACUSAGE']; ?>" size="32">
        </font></td>
         <td width="100" align="right" nowrap><font size="-1" face="Arial, Helvetica, sans-serif">accès 
        / débit:</font></td>
      <td><font size="-1" face="Arial, Helvetica, sans-serif"> 
        <input type="text" name="acces_debit" value="<?php echo $row_modifclient['acces_debit']; ?>" size="32">
        </font></td>
    </tr>
    <tr valign="baseline"> 
      <td width="100" align="right" nowrap><font size="-1" face="Arial, Helvetica, sans-serif">Commentaire:</font></td>
      <td><font size="-1" face="Arial, Helvetica, sans-serif"> 
        <input type="text" name="commentaire" value="<?php echo $row_modifclient['commentaire']; ?>" size="32">
        </font></td>
    </tr>
    <tr valign="baseline"> 
      <td width="100" align="right" nowrap>&nbsp;</td>
      <td><input type="submit" value="Mettre à jour l'enregistrement"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form1">
  <input type="hidden" name="ddp" value="<?php echo $row_modifclient['societe']; ?>">
 </form> 
et voici le message d'erreur:
Notice: Undefined variable: POST in c:\easyphp\www\consultation\modifcoloc.php on line 50

Notice: Undefined variable: POST in c:\easyphp\www\consultation\modifcoloc.php on line 51

Warning: sprintf(): Too few arguments in c:\easyphp\www\consultation\modifcoloc.php on line 54
Query est vide
Avez vous une idée de mon pb

Posté : 15 nov. 2005, 18:06
par rami
J'ai corrigé ton code en remplacant tous les HTTP_.. par leur équivalent car leur utilisation est dépréciée. De plus, les erreurs lignes 50 et 51 étaient dues à un oubli de "_" devant POST.
<?php
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . $_SERVER['QUERY_STRING'];
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE coloc SET `PEC`=%s, finddp=%s, IDFACUSAGE=%s, acces_debit=%s, commentaire=%s WHERE societe=%s",
                       GetSQLValueString($_POST['PEC'], "text"),
                       GetSQLValueString($_POST['finddp'], "text"),
                       GetSQLValueString($_POST['IDFACUSAGE'], "text"),
                       GetSQLValueString($_POST['acces_debit'], "text"),
                       GetSQLValueString($_POST['commentaire'], "text"));

  mysql_select_db($base, $connexion);
  $Result1 = mysql_query($updateSQL, $connexion) or die(mysql_error());

  $updateGoTo = "confirmation-operation.htm";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

mysql_select_db($base, $connexion);
$query_modifclient = "SELECT * FROM coloc WHERE societe='$societe'";
$modifclient = mysql_query($query_modifclient, $connexion) or die(mysql_error());
$row_modifclient = mysql_fetch_assoc($modifclient);
$totalRows_modifclient = mysql_num_rows($modifclient);

mysql_free_result($modifclient);
?><body>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  <p align="center"><strong><em><u><i><b><font color="#993333" size="6">Modification
    des Infos Client</font></b></i></u></em></strong></p>
  <table width="600" height="988" align="center">
    <tr valign="baseline">
      <td width="100" align="right" nowrap><font size="-1" face="Arial, Helvetica, sans-serif">Date
        PEC:</font></td>
      <td><font size="-1" face="Arial, Helvetica, sans-serif">
        <input type="text" name="date_PEC" value="<?php echo $row_modifclient['PEC']; ?>" size="32">
        </font></td>
          <td width="100" align="right" nowrap><font size="-1" face="Arial, Helvetica, sans-serif">Date
        d instal:</font></td>
      <td><font size="-1" face="Arial, Helvetica, sans-serif">
        <input type="text" name="date_d_instal" value="<?php echo $row_modifclient['finddp']; ?>" size="32">
        </font></td>
    </tr>
    <tr valign="baseline">
      <td width="100" align="right" nowrap><font size="-1" face="Arial, Helvetica, sans-serif">IDFACUSAGE:</font></td>
      <td><font size="-1" face="Arial, Helvetica, sans-serif">
        <input type="text" name="IDFACUSAGE" value="<?php echo $row_modifclient['IDFACUSAGE']; ?>" size="32">
        </font></td>
         <td width="100" align="right" nowrap><font size="-1" face="Arial, Helvetica, sans-serif">accès
        / débit:</font></td>
      <td><font size="-1" face="Arial, Helvetica, sans-serif">
        <input type="text" name="acces_debit" value="<?php echo $row_modifclient['acces_debit']; ?>" size="32">
        </font></td>
    </tr>
    <tr valign="baseline">
      <td width="100" align="right" nowrap><font size="-1" face="Arial, Helvetica, sans-serif">Commentaire:</font></td>
      <td><font size="-1" face="Arial, Helvetica, sans-serif">
        <input type="text" name="commentaire" value="<?php echo $row_modifclient['commentaire']; ?>" size="32">
        </font></td>
    </tr>
    <tr valign="baseline">
      <td width="100" align="right" nowrap>&nbsp;</td>
      <td><input type="submit" value="Mettre à jour l'enregistrement"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form1">
  <input type="hidden" name="ddp" value="<?php echo $row_modifclient['societe']; ?>">
</form>

Posté : 15 nov. 2005, 18:32
par philoult
je ne vois pas où tu as modifier des "" ?

Posté : 15 nov. 2005, 18:41
par rami
 GetSQLValueString($POST['PEC'], "text"),
                       GetSQLValueString($POST['finddp'], "text"),
Remplacé par
 GetSQLValueString($_POST['PEC'], "text"),
                       GetSQLValueString($_POST['finddp'], "text"),
Les erreurs lignes 50 et 51 étaient dues à l'oubli de _ devant POST.

Posté : 16 nov. 2005, 12:37
par philoult
j'ai toujours le même probleme même apres ta correction
je rajoute la definition de la fonction GetSQLValueString que j'avais pas mise:
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
?>