{MySQL} prob UPDATE SET

Résolu
Bonjour,
je souhaite créer une page grâce à laquelle je puisse mettre à jour un tableau (base mysql).

Etant novice, je ne sais pas comment m'y prendre et pour le moment en suis à ce résultat :

Message après post :
Fatal error: Call to a member function update() on a non-object in /mnt/sites/altordj.com/web/pokatest/rien.php on line 28

script :
<table  align=center aligncellpadding=0 border=1 cellspacing=0>
  <tr>
    <td width="40" align=center><B>Rang</B></td>
    <td width="75" align=left><B>Joueur</B></td>
    <td width="40" align=right><B>Jan.</B></td>
    <td width="40" align=right><B>Fév.</B></td>
    <td width="40" align=right><B>Mars</B></td>
    <td width="40" align=right><B>Avr.</B></td>
    <td width="40" align=right><B>Mai</B></td>
    <td width="40" align=right><B>Juin</B></td>
    <td width="40" align=right><B>Juil.</B></td>
    <td width="40" align=right><B>Août</B></td>
    <td width="40" align=right><B>Sept.</B></td>
    <td width="40" align=right><B>Oct.</B></td>
    <td width="40" align=right><B>Nov.</B></td>
    <td width="40" align=right><B>Déc.</B></td>
    <td width="60" align=right><B>Total</B></td>
  </tr>

  <?php
include("config.php");

mysql_connect("$dbhost", "$dblogin", "$dbpassword");
mysql_select_db("$dbname");


$action=$_POST["action"]; 

La ligne 28:
if($action=="update"){ $dbname->update("$dbtable3 SET Joueur='joueur',Janvier='janvier',Fevrier='fevrier',Mars='mars',Avril='avril',Mai='mai',Juin='juin',Juillet='juillet',Aout='aout',Septembre='septembre',Octobre='octobre',Novembre='novembre',Decembre='decembre'");
 echo"<A HREF='Javascript:history.go(-1)'>Retour</A>"; 
 exit; 
}

echo"<form name='pok_res' method='post' action='rien.php'>";

$reponses = mysql_query("SELECT Joueur,Janvier,Fevrier,Mars,Avril,Mai,Juin,Juillet,Aout,Septembre,Octobre,Novembre,Decembre,(Janvier+Fevrier+Mars+Avril+Mai+Juin+Juillet+Aout+Septembre+Octobre+Novembre+Decembre) as total FROM $dbtable3 ORDER BY total DESC");
$numligne="1";
while ($donnees = mysql_fetch_array($reponses))
{ 


echo





  '<tr>


    <td width="40" align=center><B>' .$numligne. '</BR></td>
    <td width="75" align=left><input type=text name=joueur size=20 value='.$donnees['Joueur'].'></td>
    <td width="40" align=right><input type=text name=janvier size=5 value=' .$donnees['Janvier']. '></td>
    <td width="40" align=right><input type=text name=fevrier size=5 value=' .$donnees['Fevrier']. '></td>
    <td width="40" align=right><input type=text name=mars size=5 value=' .$donnees['Mars']. '></td>
    <td width="40" align=right><input type=text name=avril size=5 value=' .$donnees['Avril']. '></td>
    <td width="40" align=right><input type=text name=mai size=5 value=' .$donnees['Mai']. '></td>
    <td width="40" align=right><input type=text name=juin size=5 value=' .$donnees['Juin']. '></td>
    <td width="40" align=right><input type=text name=juillet size=5 value=' .$donnees['Juillet']. '></td>
    <td width="40" align=right><input type=text name=aout size=5 value=' .$donnees['Aout']. '></td>
    <td width="40" align=right><input type=text name=septembre size=5 value=' .$donnees['Septembre']. '></td>
    <td width="40" align=right><input type=text name=octobre size=5 value=' .$donnees['Octobre']. '></td>
    <td width="40" align=right><input type=text name=novembre size=5 value=' .$donnees['Novembre']. '></td>
    <td width="40" align=right><input type=text name=decembre size=5 value=' .$donnees['Decembre']. '></td>
    <td width="40" align=right><B>' .$donnees['total']. '</B></td>
      </tr><P> ';
$numligne++ ;
     }
mysql_close();
?> 
</table>
<input type='hidden' name='action' value='update'>
<input type='submit' value='Envoyer'>
</form>


Donc si quelqu'un trouve mon erreur, ou peut m'expliquer comment faire plus simple, ce serait vraiment super sympa.

D'avance merci.
Configuration: Windows XP
Safari 530.5

4 réponses

  1. Hello,
    ça m'a l'air bien compliqué d'utiliser un tableau pour faire un update. Qu'importe la structure de ton projet la syntaxe est pas bonne.
    UPDATE table SET champ1Amodfier = 'valeurAffectation', champ2Amodfier = 'valeurAffectation' WHERE id = 'clé' ...

    'valeurAffectation' est une variable dynamique de php le plus souvent,

    Normail qu'il comprenne pas "update(" <-- ce n'est pas la syntaxe.
    Là il comprend qu'il faut appeler une fonction qui s'appelle update. Ce qui ne risque pâs parce que update est un mot réservé au php
    1. Wowww... heu moi pas parler langue à vous...

      Si t'arrives à me montrer un exemple simple de formulaire pour mettre à jour une table je pourrai l'adapter je suppose... mais c'est tellement basique que j'en trouve pas :-(

      (*dsl dla réaction (lol))

      Je te remercie d'avoir daigné répondre à mon message! !
      1. Relis bien mon message précédent je t'ai déjà expliqué pk l'erreur est remontée.
        Le problème est d'ordre syntaxique.
        En SQL un update c'est pas comme ça --> update("$dbtable3 SET

        A toi de jouer
        1. Un ami m'a développé ça je vous donne les scripts (en espérant que ça puisse aider qqun)

          sbpoker.php:
          
          <head>
          <style type="text/css">
          .style1 {
              text-align: center;
          }
          </style>
          </head>
          
          <?php
           
          include("config.php");
          
          mysql_connect("$dbhost", "$dblogin", "$dbpassword");
          mysql_select_db("$dbname");
          
          $query = 'SELECT * FROM '.$dbtable3;
          $result = mysql_query($query);
          
          ?>
          <form action="sbupdate.php" method="post">
          
          <table align=center aligncellpadding=0 border=1 cellspacing=0>
            <tr>
              <td width="75" align=left><B>Joueur</B></td>
              <td width="40" align=right><B>Jan.</B></td>
              <td width="40" align=right><B>Fév.</B></td>
              <td width="40" align=right><B>Mars</B></td>
              <td width="40" align=right><B>Avr.</B></td>
              <td width="40" align=right><B>Mai</B></td>
              <td width="40" align=right><B>Juin</B></td>
              <td width="40" align=right><B>Juil.</B></td>
              <td width="40" align=right><B>Août</B></td>
              <td width="40" align=right><B>Sept.</B></td>
              <td width="40" align=right><B>Oct.</B></td>
              <td width="40" align=right><B>Nov.</B></td>
              <td width="40" align=right><B>Déc.</B></td>
              <?php //Supprimer la ligne ci-dessous pour enlever l'option de suppression ?>
              <td width="40" align=right><B>Suppr.</B></td>
            </tr>
            
          <?php
          
          $i=0;
          $n=0;
          
          while ($val = mysql_fetch_array($result)) {
                // ------------------------------------------
                // DONNEES A AFFICHER dans les cellules
                echo '<input type="hidden" name="ID['.$i.']" value="'.$val['id'].'">';
                echo '<tr>';
                echo '<td width="75" align=left><input type=text name=Joueur['.$i.'] size=6 value="'.$val['joueur'].'"></td>';
                echo '<td width="40" align=right><input type=text name=Janvier['.$i.'] size=1 value="'.$val['janvier'].'"></td>';
                echo '<td width="40" align=right><input type=text name=Fevrier['.$i.'] size=1 value="'.$val['fevrier'].'"></td>';
                echo '<td width="40" align=right><input type=text name=Mars['.$i.'] size=1 value="'.$val['mars'].'"></td>';
                echo '<td width="40" align=right><input type=text name=Avril['.$i.'] size=1 value="'.$val['avril'].'"></td>';
                echo '<td width="40" align=right><input type=text name=Mai['.$i.'] size=1 value="'.$val['mai'].'"></td>';
                echo '<td width="40" align=right><input type=text name=Juin['.$i.'] size=1 value="'.$val['juin'].'"></td>';
                echo '<td width="40" align=right><input type=text name=Juillet['.$i.'] size=1 value="'.$val['juillet'].'"></td>';
                echo '<td width="40" align=right><input type=text name=Aout['.$i.'] size=1 value="'.$val['aout'].'"></td>';
                echo '<td width="40" align=right><input type=text name=Septembre['.$i.'] size=1 value="'.$val['septembre'].'"></td>';
                echo '<td width="40" align=right><input type=text name=Octobre['.$i.'] size=1 value="'.$val['octobre'].'"></td>';
                echo '<td width="40" align=right><input type=text name=Novembre['.$i.'] size=1 value="'.$val['novembre'].'"></td>';
                echo '<td width="40" align=right><input type=text name=Decembre['.$i.'] size=1 value="'.$val['decembre'].'"></td>';
                //Supprimer la ligne ci-dessous pour enlever l'option de suppression
                echo '<td width="40" align=center><input type=checkbox name=Chk['.$i.']></td>';
                echo '</tr>';
                
                $n = $i;
                
                $i++;
                // ------------------------------------------
          }
          ?>
          </table>
          <?php
          
              mysql_close();
              
          ?>
          <input type="hidden" name="n" value="<?php echo $n; ?>">
          <br>
              <div class="style1">
          <input type="submit" name="envoie" value="Modifier">
              </div>
          </form>
          


          sbupdate.php:
          <?php
          
          include("config.php");
          
          mysql_connect("$dbhost", "$dblogin", "$dbpassword");
          mysql_select_db("$dbname");
          
          
          $i=0;
          
          while ($i <= $_POST['n']) {    
          
          //Supprimer tout le contenu du IF et le IF, et supprimer QUE le ELSE (pas le contenu!) pour enlever la fonctione de suppression
          if ($_POST['Chk'][$i]) {
          
              $sql = "DELETE FROM ".$dbtable3." WHERE id='".$_POST['ID'][$i]."'";
              echo "Joueur: ".$_POST['Joueur'][$i]." supprimé<br>";
          }
          
          else {
              $sql = "UPDATE ".$dbtable3." SET joueur='".$_POST['Joueur'][$i]."', janvier='".$_POST['Janvier'][$i]."', fevrier='".$_POST['Fevrier'][$i]."', mars='".$_POST['Mars'][$i]."',";
              $sql.= "avril='".$_POST['Avril'][$i]."', mai='".$_POST['Mai'][$i]."', juin='".$_POST['Juin'][$i]."', juillet='".$_POST['Juillet'][$i]."', aout='".$_POST['Aout'][$i]."',";
              $sql.= "septembre='".$_POST['Septembre'][$i]."', octobre='".$_POST['Octobre'][$i]."', novembre='".$_POST['Novembre'][$i]."', decembre='".$_POST['Decembre'][$i]."' WHERE id='".$_POST['ID'][$i]."'";
          
          }
              //echo $sql."<br>";
          
              mysql_query($sql);
              
              $i++;
          
          
          }
          
          mysql_close();
          
          echo "OK !";
          
          ?>
          <br><br>
          <a href="#" onclick="history.back();">Retour</a>