IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

modifier champ texte en cases à cocher multiples


Sujet :

Langage PHP

  1. #1
    Nouveau membre du Club
    Inscrit en
    Mars 2006
    Messages
    89
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 89
    Points : 30
    Points
    30
    Par défaut modifier champ texte en cases à cocher multiples
    Bonjour tout le monde ,

    J'ai à l'intérieur d'un formulaire, un champ texte nommé "features".
    Je l'ai donc modifié dans ma base et remplacé par un champ SET avec des valeurs ('ABS', 'AIRBAGS', 'CLIMATISATION').
    J' ai donc remplacé mon champ texte dans mon formulaire par 3 checkbox :

    <input type="checkbox" name="features[]" value="ABS" />ABS
    <input type="checkbox" name="features[]" value="AIRBAGS" />AIRBAGS
    <input type="checkbox" name="features[]" value="CLIMATISATION" />CLIMATISATION

    Ma question est la suivante :
    Comment insérer le contenu de ces cases à cocher dans mon champ "features" dans ma table ?

    Voici le code actuel:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    	<?	$sql = "INSERT INTO ".$db_prefix."cars SET
    					member_id='".$HTTP_POST_VARS["member_id"]."',
    					stock='".add_slashes($HTTP_POST_VARS['stock'])."',
    					stored='".$HTTP_POST_VARS['stored_year']."-".$HTTP_POST_VARS['stored_month']."-".$HTTP_POST_VARS['stored_day']."',
    					year='".add_slashes($HTTP_POST_VARS['year'])."',
    					model='".add_slashes($HTTP_POST_VARS['model'])."',
    					type='".add_slashes($HTTP_POST_VARS['type'])."',
    					engine='".add_slashes($HTTP_POST_VARS['engine'])."',
    					trans='".add_slashes($HTTP_POST_VARS['trans'])."',
    					drive='".add_slashes($HTTP_POST_VARS['drive'])."',
    					color='".add_slashes($HTTP_POST_VARS['color'])."',
    					millage='".add_slashes($HTTP_POST_VARS['millage'])."',
    					vin='".add_slashes($HTTP_POST_VARS['vin'])."',
    					price='".add_slashes(strip_out($HTTP_POST_VARS['price']))."',
    					low='".add_slashes(strip_out($HTTP_POST_VARS['low']))."',
    					high='".add_slashes(strip_out($HTTP_POST_VARS['high']))."',
    					features='".add_slashes($HTTP_POST_VARS['features'])."',
    					comments='".add_slashes($HTTP_POST_VARS['comments'])."',
    					certified='".add_slashes($HTTP_POST_VARS['certified'])."',
    					special= '".$special."'";
     
    		if(@mysql_query($sql))
    			die(header("Location: index.php?status=insert"));
    		else
    			$error_msg = "Impossible de valider cette entree.<br>- Numero de stock doit etre unique.";
    	}
    	else//if($error_msg == "")
    		$error_msg = "Impossible de valider cette entree.<br>".$error_msg;
     
    	$member_id = $HTTP_POST_VARS["member_id"];
    	$stock = $HTTP_POST_VARS["stock"];
    	$stored_month = $HTTP_POST_VARS["stored_month"];
    	$stored_day = $HTTP_POST_VARS["stored_day"];
    	$stored_year = $HTTP_POST_VARS["stored_year"];
    	$year = $HTTP_POST_VARS["year"];
    	$model = $HTTP_POST_VARS["model"];
    	$type = $HTTP_POST_VARS["type"];
    	$engine = $HTTP_POST_VARS["engine"];
    	$trans = $HTTP_POST_VARS["trans"];
    	$drive = $HTTP_POST_VARS["drive"];
    	$color = $HTTP_POST_VARS["color"];
    	$millage = $HTTP_POST_VARS["millage"];
    	$vin = $HTTP_POST_VARS["vin"];
    	$price = $HTTP_POST_VARS["price"];
    	$low = $HTTP_POST_VARS["low"];
    	$high = $HTTP_POST_VARS["high"];
    	$features = $HTTP_POST_VARS["features"];
    	$comments = $HTTP_POST_VARS["comments"];	
    	$certified = $HTTP_POST_VARS["certified"];	
    }
    else
    {
           $stock = "";
    		 $stored_month = date("m");
    		 $stored_day = date("d");
    		 $stored_year = date("Y");
    	    $year = "";
    		 $model = "";
    		 $type = "";
    		 $engine = "";
    		 $trans = "";
    		 $drive = "";
    		 $color = "";
    		 $millage = "";
    		 $vin = "";
    		 $price = "";
    		 $low = "";
    		 $high = "";
    		 $features = "";
    		 $comments = "";
    		 $special ="";
    		 $member_id=$HTTP_SESSION_VARS['ses_mem_id'];
    		 $certified="0";
     
    }
     
    ?>

    Merci pour votre aide

  2. #2
    Membre expert Avatar de Amara
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    2 688
    Détails du profil
    Informations personnelles :
    Localisation : France, Sarthe (Pays de la Loire)

    Informations forums :
    Inscription : Juillet 2004
    Messages : 2 688
    Points : 3 115
    Points
    3 115
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    $str = "";
    foreach($_POST['features'] as $feature)
      $str .= " " . $feature;
    Quelque chose dans le genre...

  3. #3
    Nouveau membre du Club
    Inscrit en
    Mars 2006
    Messages
    89
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 89
    Points : 30
    Points
    30
    Par défaut oups !
    hello,

    merci pour ton aide, mais à quel endroit dois-je le placer ?

  4. #4
    Membre expert Avatar de Amara
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    2 688
    Détails du profil
    Informations personnelles :
    Localisation : France, Sarthe (Pays de la Loire)

    Informations forums :
    Inscription : Juillet 2004
    Messages : 2 688
    Points : 3 115
    Points
    3 115
    Par défaut
    Citation Envoyé par gator
    hello,

    merci pour ton aide, mais à quel endroit dois-je le placer ?
    Avant de construire ta requête par exemple...
    Et dans $sql tu mets $str là où tu veux mettre les "features".

  5. #5
    Nouveau membre du Club
    Inscrit en
    Mars 2006
    Messages
    89
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 89
    Points : 30
    Points
    30
    Par défaut aurais je fait une erreur ?
    Voici mon code, le formulaire se valide, aucune erreur retournée, mais rien dans la base :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    if($HTTP_SERVER_VARS['REQUEST_METHOD']=="POST") 
    {
    	/**** SERVER VALIDATION ****/
    	if(!(chk($HTTP_POST_VARS['member_id'],"IsSelected")))
    		$error_msg.= "- Please select a Dealer<br>";
    	if(!(chk($HTTP_POST_VARS['stock'],"IsNotEmpty")))
    		$error_msg.= "- Please enter a Stock number<br>";
    	if(!(chk($HTTP_POST_VARS['year'],"IsNotEmpty,IsNumber")))
    	    $error_msg.= "- Please enter a Year<br>";
    	if(!(chk($HTTP_POST_VARS['model'],"IsNotEmpty")))
    	    $error_msg.= "- Please enter a Make<br>";
    	if(!(chk($HTTP_POST_VARS['type'],"IsNotEmpty")))
    	    $error_msg.= "- Please enter a Model<br>";
    	if(!(chk($HTTP_POST_VARS['engine'],"IsNotEmpty")))
    	    $error_msg.= "- Please enter an Engine<br>";
    	if(!(chk($HTTP_POST_VARS['trans'],"IsNotEmpty")))
    	    $error_msg.= "- Please enter a Trans<br>";
    	if(!(chk($HTTP_POST_VARS['drive'],"IsNotEmpty")))
    	    $error_msg.= "- Please enter a Drive<br>";
    	if(!(chk($HTTP_POST_VARS['color'],"IsNotEmpty")))
    	    $error_msg.= "- Please enter a Color<br>";
    	if(!(chk($HTTP_POST_VARS['millage'],"IsNotEmpty,IsNumber")))
    	    $error_msg.= "- Please enter a valid numeric value for Mileage<br>";
    	if(!(chk($HTTP_POST_VARS['price'],"IsMoney")))
    	    $error_msg.= "- Please enter a valid money value for Price<br>";
    	/*
    	if(!(chk($HTTP_POST_VARS['low'],"IsMoney")))
    	    $error_msg.= "- Please enter a valid money value for Low Book<br>";
    	if(!(chk($HTTP_POST_VARS['high'],"IsMoney")))
    	    $error_msg.= "- Please enter a valid money value for High Book<br>";
    	*/
    	if(!(chk($HTTP_POST_VARS['certified'],"IsSelected")))
    		$error_msg.= "- Please select an option for Certified<br>";
     
    	if(isset($HTTP_POST_VARS['special']))
    		$special="Y";
    	else
    		$special="N";
     
    		$str = "";
    foreach($_POST['features'] as $feature)
      $str .= " " . $feature;
     
    	if($error_msg == "") 
     
    	{
    		#############################################################################
    		#	IF MAGIC QUOTE IN PHP.INI IS SET OFF ADD SLASHES TO SUBMITED VARIABLES	#
    		#############################################################################
    		$sql = "INSERT INTO ".$db_prefix."cars SET
    					member_id='".$HTTP_POST_VARS["member_id"]."',
    					stock='".add_slashes($HTTP_POST_VARS['stock'])."',
    					stored='".$HTTP_POST_VARS['stored_year']."-".$HTTP_POST_VARS['stored_month']."-".$HTTP_POST_VARS['stored_day']."',
    					year='".add_slashes($HTTP_POST_VARS['year'])."',
    					model='".add_slashes($HTTP_POST_VARS['model'])."',
    					type='".add_slashes($HTTP_POST_VARS['type'])."',
    					engine='".add_slashes($HTTP_POST_VARS['engine'])."',
    					trans='".add_slashes($HTTP_POST_VARS['trans'])."',
    					drive='".add_slashes($HTTP_POST_VARS['drive'])."',
    					color='".add_slashes($HTTP_POST_VARS['color'])."',
    					millage='".add_slashes($HTTP_POST_VARS['millage'])."',
    					vin='".add_slashes($HTTP_POST_VARS['vin'])."',
    					price='".add_slashes(strip_out($HTTP_POST_VARS['price']))."',
    					low='".add_slashes(strip_out($HTTP_POST_VARS['low']))."',
    					high='".add_slashes(strip_out($HTTP_POST_VARS['high']))."',
    					features='".add_slashes($HTTP_POST_VARS['features'])."',
    					comments='".add_slashes($HTTP_POST_VARS['comments'])."',
    					certified='".add_slashes($HTTP_POST_VARS['certified'])."',
    					special= '".$special."'";
     
    		if(@mysql_query($sql))
    			die(header("Location: index.php?status=insert"));
    		else
    			$error_msg = "Record was not inserted because of invalid data posted.<br>- Stock must be unique.";
    	}
    	else//if($error_msg == "")
    		$error_msg = "Record was not inserted because of invalid data posted.<br>".$error_msg;
     
    	$member_id = $HTTP_POST_VARS["member_id"];
    	$stock = $HTTP_POST_VARS["stock"];
    	$stored_month = $HTTP_POST_VARS["stored_month"];
    	$stored_day = $HTTP_POST_VARS["stored_day"];
    	$stored_year = $HTTP_POST_VARS["stored_year"];
    	$year = $HTTP_POST_VARS["year"];
    	$model = $HTTP_POST_VARS["model"];
    	$type = $HTTP_POST_VARS["type"];
    	$engine = $HTTP_POST_VARS["engine"];
    	$trans = $HTTP_POST_VARS["trans"];
    	$drive = $HTTP_POST_VARS["drive"];
    	$color = $HTTP_POST_VARS["color"];
    	$millage = $HTTP_POST_VARS["millage"];
    	$vin = $HTTP_POST_VARS["vin"];
    	$price = $HTTP_POST_VARS["price"];
    	$low = $HTTP_POST_VARS["low"];
    	$high = $HTTP_POST_VARS["high"];
    	$str = $HTTP_POST_VARS["str"];
    	$comments = $HTTP_POST_VARS["comments"];	
    	$certified = $HTTP_POST_VARS["certified"];	
    }
    else
    {
           $stock = "";
    		 $stored_month = date("m");
    		 $stored_day = date("d");
    		 $stored_year = date("Y");
    	    $year = "";
    		 $model = "";
    		 $type = "";
    		 $engine = "";
    		 $trans = "";
    		 $drive = "";
    		 $color = "";
    		 $millage = "";
    		 $vin = "";
    		 $price = "";
    		 $low = "";
    		 $high = "";
    		 $str = "";
    		 $comments = "";
    		 $special ="";
    		 $member_id=$HTTP_SESSION_VARS['ses_mem_id'];
    		 $certified="0";
     
    }//e

  6. #6
    Membre expert Avatar de Amara
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    2 688
    Détails du profil
    Informations personnelles :
    Localisation : France, Sarthe (Pays de la Loire)

    Informations forums :
    Inscription : Juillet 2004
    Messages : 2 688
    Points : 3 115
    Points
    3 115
    Par défaut
    Enlève le @ devant ton mysql_query, et l'idéal c'est de faire un "mysql_query(...) or die (mysql_error());" pour voir ce qui va pas, je te laisse adapter à ton code...

  7. #7
    Nouveau membre du Club
    Inscrit en
    Mars 2006
    Messages
    89
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 89
    Points : 30
    Points
    30
    Par défaut marche pas...
    j'ai enlevé @, testé, puis remplacé par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    mysql_query($sql) or die (mysql_error());
    J'essaie différentes choses, cela ne fonctionne pas., j'ai une page blanche

    Il est évident que la connerie vient de moi

  8. #8
    Membre expert Avatar de Amara
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    2 688
    Détails du profil
    Informations personnelles :
    Localisation : France, Sarthe (Pays de la Loire)

    Informations forums :
    Inscription : Juillet 2004
    Messages : 2 688
    Points : 3 115
    Points
    3 115
    Par défaut
    Essaie de mettre des echo un peu partout pour voir si tu rentres bien dans tes if comme tu devrais.

Discussions similaires

  1. Liaison entre champ texte et case à cocher
    Par Robjerey dans le forum Balisage (X)HTML et validation W3C
    Réponses: 4
    Dernier message: 16/12/2014, 22h47
  2. [WD-2007] champs texte et case à cocher
    Par f69815 dans le forum Word
    Réponses: 23
    Dernier message: 30/11/2011, 23h21
  3. [MIGRATION] champ de type "case à cocher"
    Par The_Nail dans le forum MS SQL Server
    Réponses: 9
    Dernier message: 10/05/2011, 11h07
  4. Réponses: 5
    Dernier message: 23/01/2009, 15h26
  5. Réponses: 1
    Dernier message: 01/08/2006, 17h01

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo