Entrer valeur d'une variable dans BDD

Fermé
glagla - 5 janv. 2012 à 17:58
ferranzo Messages postés 27 Date d'inscription dimanche 30 novembre 2008 Statut Membre Dernière intervention 8 janvier 2012 - 7 janv. 2012 à 22:51
Bonjour,

Comment faire pour ajouter une valeur dans un champ vide ?

En fait j'ai ma table avec user-id,id,type,box,etc... qui lors de l'inscription du membre sur mon site se remplit bien avec le nom, pseudo et tout de l'utilisateur, mais il y a un champ
que je ne "remplis" pas.

Par exemple nomdejeunefille

Et que l'utilisateur peut choisir par la suite de vouloir le remplir ce champs

Comment insérer la valeur dans le champ de ma table et pour cet utilisateur précis ?

car quand les données de l'utilisateur sont envoyées sur ma table cela créer une nouvelle entrée et çà laisse un champ vide.

Comment par la suite envoyé des données dans ce champ spécifiques ?

Voilà j'espère avoir été à peu près compréhensible..

Merci d'avance pour vos réponses !

3 réponses

Autumn`Tears Messages postés 1054 Date d'inscription samedi 14 mars 2009 Statut Membre Dernière intervention 23 octobre 2013 145
5 janv. 2012 à 18:02
Salut,

Tu peux quand même faire ça : "insert into (champ,nomdejeunefille,champ) values ('".$val1."','".$_POST['nomdejeunefille']."','".$val2."')";
Ça ne devrait pas poser de problème, mais il doit falloir avoir dans ta base le champ à DEFAULT NULL. (à vérifier)
0
jisisv Messages postés 3645 Date d'inscription dimanche 18 mars 2001 Statut Modérateur Dernière intervention 15 janvier 2017 934
Modifié par jisisv le 5/01/2012 à 18:14
Utilise la clause UPDATE.
exemple sous MySQL:
mysql> select *  from random2 where date1='2012/01/03'; 
+------------+-------+ 
| date1      | date2 | 
+------------+-------+ 
| 2012-01-03 | NULL  | 
+------------+-------+ 
1 row in set (0.00 sec) 

mysql> update random2 set date2='1970/01/01' ; 
Query OK, 201 rows affected (0.00 sec) 
Rows matched: 201  Changed: 201  Warnings: 0 

mysql> select *  from random2 where date1='2012/01/03'; 
+------------+------------+ 
| date1      | date2      | 
+------------+------------+ 
| 2012-01-03 | 1970-01-01 | 
+------------+------------+ 
1 row in set (0.00 sec)
mysql> help update;;
Name: 'UPDATE'
Description:
Syntax:
Single-table syntax:

UPDATE [LOW_PRIORITY] [IGNORE] table_reference
    SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
    [WHERE where_condition]
    [ORDER BY ...]
    [LIMIT row_count]

Multiple-table syntax:

UPDATE [LOW_PRIORITY] [IGNORE] table_references
    SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
    [WHERE where_condition]

For the single-table syntax, the UPDATE statement updates columns of
existing rows in the named table with new values. The SET clause
indicates which columns to modify and the values they should be given.
Each value can be given as an expression, or the keyword DEFAULT to set
a column explicitly to its default value. The WHERE clause, if given,
specifies the conditions that identify which rows to update. With no
WHERE clause, all rows are updated. If the ORDER BY clause is
specified, the rows are updated in the order that is specified. The
LIMIT clause places a limit on the number of rows that can be updated.

For the multiple-table syntax, UPDATE updates rows in each table named
in table_references that satisfy the conditions. In this case, ORDER BY
and LIMIT cannot be used.

where_condition is an expression that evaluates to true for each row to
be updated. For expression syntax, see
https://dev.mysql.com/doc/refman/8.0/en/expressions.html

table_references and where_condition are is specified as described in
https://dev.mysql.com/doc/refman/8.0/en/select.html

You need the UPDATE privilege only for columns referenced in an UPDATE
that are actually updated. You need only the SELECT privilege for any
columns that are read but not modified.

The UPDATE statement supports the following modifiers:

o With the LOW_PRIORITY keyword, execution of the UPDATE is delayed
  until no other clients are reading from the table. This affects only
  storage engines that use only table-level locking (such as MyISAM,
  MEMORY, and MERGE).

o With the IGNORE keyword, the update statement does not abort even if
  errors occur during the update. Rows for which duplicate-key
  conflicts occur are not updated. Rows for which columns are updated
  to values that would cause data conversion errors are updated to the
  closest valid values instead.

URL: https://dev.mysql.com/doc/refman/8.0/en/update.html


Gates gave ^H sold you the windows.
GNU gave us the whole house.(Alexandrin)
0
ferranzo Messages postés 27 Date d'inscription dimanche 30 novembre 2008 Statut Membre Dernière intervention 8 janvier 2012
7 janv. 2012 à 22:51
UPDATE user set nomdejeunefille='une valeur' where id=idDelaPersonne
0