Modifier des enregisrements en PHP

cs_zeitoun69 Messages postés 23 Date d'inscription vendredi 31 décembre 2004 Statut Membre Dernière intervention 29 août 2010 - 13 janv. 2008 à 16:21
cs_zeitoun69 Messages postés 23 Date d'inscription vendredi 31 décembre 2004 Statut Membre Dernière intervention 29 août 2010 - 5 avril 2008 à 10:26
Bonjour,
concernant des enregistrements d'une base mySQL, j'arrive a modifier chaque enregistrement séparement ou encore a affiché un champ pour tous les enregistrements mais je n'arrive pas a  modifier a l'aide d'un formulaire un champ pour les diffémrents enregistrements mais comment les modifier tous dans cette page?
voici un extrait de mon code dans <head> :

mysql_select_db($database_apartmentparis, $apartmentparis);
$query_liste = "SELECT * FROM locations2";
$liste = mysql_query($query_liste, $apartmentparis) or die(mysql_error());
$row_liste = mysql_fetch_assoc($liste);
$totalRows_liste = mysql_num_rows($liste);

mysql_select_db($database_apartmentparis, $apartmentparis);
$query_ajout = sprintf("SELECT * FROM locations2", $colname_ajout);
$ajout = mysql_query($query_ajout, $apartmentparis) or die(mysql_error());
$row_ajout = mysql_fetch_assoc($ajout);
$totalRows_ajout = mysql_num_rows($ajout);

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

$liste_mini_week=$_POST[mini_week];
$liste_mini_week_avant=$_POST[mini_weekavant];
$liste_mini_day=$_POST[mini_day];
$liste_mini_day_avant=$_POST[mini_dayavant];
$liste_id=$_POST[Id];

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form3")) {
  $updateSQL = sprintf("UPDATE locations2 SET mini_day=%s, mini_week=%s WHERE Id=$liste_id[$i]",
                       GetSQLValueString($_POST['Id'], "text"),
                       GetSQLValueString($_POST['mini_day[]'], "text"),
                       GetSQLValueString($_POST['mini_week[]'], "text"));

  mysql_select_db($database_apartmentparis, $apartmentparis);
  $Result = mysql_query($updateSQL, $apartmentparis) or die(mysql_error());

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

?>

et dans le j'ai ca :

 " size="10" />
              

Par avance merci

Zeitoun

2 réponses

Utilisateur anonyme
15 janv. 2008 à 17:39
salut ...

alors premier conseil, ta fonction getValueString() me fait penser à du code dreamweaver. Perso un conseil oublie le ...

est ce que tu peux me filer le code de tout ton formulaire stp ?
pk là je vois pas trop le truc ...

merci d'avance
0
cs_zeitoun69 Messages postés 23 Date d'inscription vendredi 31 décembre 2004 Statut Membre Dernière intervention 29 août 2010
5 avril 2008 à 10:26
Bonjour desole j'ai mis un peu de temps a reagir, voial mon code complet
mysql_select_db($database_apartmentparis, $apartmentparis);
$query_liste = "SELECT * FROM locations2";
$liste = mysql_query($query_liste, $apartmentparis) or die(mysql_error());
$row_liste = mysql_fetch_assoc($liste);
$totalRows_liste = mysql_num_rows($liste);

mysql_select_db($database_apartmentparis, $apartmentparis);
$query_ajout = sprintf("SELECT * FROM locations2", $colname_ajout);
$ajout = mysql_query($query_ajout, $apartmentparis) or die(mysql_error());
$row_ajout = mysql_fetch_assoc($ajout);
$totalRows_ajout = mysql_num_rows($ajout);

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

$liste_mini_week=$_POST[mini_week];
$liste_mini_week_avant=$_POST[mini_weekavant];
$liste_mini_day=$_POST[mini_day];
$liste_mini_day_avant=$_POST[mini_dayavant];
$liste_id=$_POST[Id];

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form3")) {
  $updateSQL = sprintf("UPDATE locations2 SET mini_day=%s, mini_week=%s WHERE Id=$liste_id[$i]",
                       GetSQLValueString($_POST['Id'], "text"),
                       GetSQLValueString($_POST['mini_day[]'], "text"),
                       GetSQLValueString($_POST['mini_week[]'], "text"));

  mysql_select_db($database_apartmentparis, $apartmentparis);
  $Result = mysql_query($updateSQL, $apartmentparis) or die(mysql_error());

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

?>

<!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=iso-8859-1" />
<title>Modification d'un appartement</title>

<link href="../apartparis.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.Style1 {
    font-size: 24px;
    font-weight: bold;
}
-->
</style>
</head>

[admin2.php Admin] ADMINISTATION DES PRIX [accueil.php accueil] 

    ----

    
   

<form action="<?php echo $editFormAction; ?>" id="form3" name="form3" method="POST">
  <label for="textfield"></label>
  <label for="label"></label>
  <label for="label2"></label>
 

 

  <label for="textarea"></label>
  <!-- début du tableau à répéter-->
         <?php do { ?>
                   
                     
           ----

                          " size="10" />
             Top of the page
       
        <!-- fin du tableau à répéter-->

      </td>

</form>

</html>
<?php
mysql_free_result($ajout);
?>

Zeitoun
0
Rejoignez-nous