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

JavaScript Discussion :

question a 15cts


Sujet :

JavaScript

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 60
    Par défaut question a 15cts
    Bonjour,
    J'ai crée un tableau dynamique sur un site que je suis en train de construire grace au javascript suivant..

    <script type="text/javascript">
    function AddRow(){
    var newRow = document.getElementById('ingredients').insertRow(-1);
    var newCell = newRow.insertCell(0);
    newCell.innerHTML = '<input name="ingredient1" type="text" />';
    newCell = newRow.insertCell(1);
    newCell.innerHTML = '<input name="ingredient2" type="text" />';
    newCell = newRow.insertCell(2);
    newCell.innerHTML = '<input name="ingredient3" type="text" />';
    }
    </script>
    j'ai place celui ci ds un formulaire et j'aurais aimé recuperer les champs ds ma bdd en sql...comemnt faire?
    merci d'avance pour votre aide...

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 60
    Par défaut
    ci dessous la tete de ma table...
    <table id="ingredients">
    <tr>
    <td>qty</td>
    <td>unit</td>
    <td>item</td>
    <td><input type="button" value="+" onClick="AddRow()" ></td>
    </tr>
    <tr>
    <td><input name="qty" type="text" size="2" /></td>
    <td><input name="unit" type="text" size="2" /></td>
    <td><input name="item" type="text" size="2" /></td>
    </tr>

    </table>

  3. #3
    Membre Expert Avatar de Djakisback
    Profil pro
    Inscrit en
    Février 2005
    Messages
    2 023
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 2 023
    Par défaut
    Salut,
    mets tout dans un <form>, sinon explique mieux ^^
    Bye

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 60
    Par défaut
    tout est deja dans un form.en fait il s'agit d'un gros form avec plusieurs tables dedans.pour les autres pa de soucis. Pour etre tres precis il s'agit d'un formulaire permettant d'ajouter des recettes de cuisine. Tout est fixe sauf le nombre d'ingredients qui different a chque recette. Dou le tableau dynamique
    je clique sur le bouton ca ajoute une ligne le but etant de les faire rentrer dans la bdd..n'hesitez pas a me dire si ya des ttruc pas clair..

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 60
    Par défaut
    et hop ici ma bdd

    CREATE TABLE `ingredients` (
    `id_ingredient` int(11) NOT NULL auto_increment,
    `id_recette` int(11) NOT NULL,
    `item` varchar(25) NOT NULL,
    `qty` int(255) NOT NULL,
    `unit` varchar(25) NOT NULL,
    PRIMARY KEY (`id_ingredient`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

  6. #6
    Membre averti
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 60
    Par défaut
    me suis dit quiitte a faire je met tout
    donc ici ma page dindex ac le form et le js

    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
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
     
    <!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>Document sans nom</title>
    <script type="text/javascript">
    function AddRow(){
        var newRow = document.getElementById('ingredients').insertRow(-1);
        var newCell = newRow.insertCell(0);
        newCell.innerHTML = '<input name="ingredient1" type="text" />';
        newCell = newRow.insertCell(1);
        newCell.innerHTML = '<input name="ingredient2" type="text" />';
    	newCell = newRow.insertCell(2);
        newCell.innerHTML = '<input name="ingredient3" type="text" />';
    }
    </script>
    </head>
     
    <body>
    <form method="post" action="add.php">
    <table>
    	<tr>
    		<td><table id="recette">
    		<tr>
    		 	<td>title</td>
    			<td><input name="title" type="text" /></td>
    		</tr>
    		<tr>
    			<td>description</td>
    			<td><textarea name="description" cols="" rows=""></textarea></td>
    		</tr>
    			<tr>
    		 	<td>yld</td>
    			<td><input name="yld" type="text" /></td>
    		</tr>
    		<tr>
    			<td>ptime</td>
    			<td><input name="ptime" type="text" /></td>
    		</tr>
    			<tr>
    		 	<td>ctime</td>
    			<td><input name="ctime" type="text" /></td>
    		</tr>
    		<tr>
    			<td>ttime</td>
    			<td><input name="ttime" type="text" /></td>
    		</tr>
    		<tr>
    		 	<td>cuisine</td>
    			<td><input name="cuisine" type="text" /></td>
    		</tr>
    		<tr>
    			<td>convenience</td>
    			<td><input name="convenience" type="text" /></td>
    		</tr>
    		<tr>
    			<td>occasion</td>
    			<td><input name="occasion" type="text" /></td>
    		</tr>
    		<tr>
    			<td>course</td>
    			<td><input name="course" type="text" /></td>
    		</tr>
     
     
    	  </table>
    	  </td>
     
    		<td> 
    		<table id="ingredients">
    	  	<tr>
    			<td>qty</td>
    			<td>unit</td>
    			<td>item</td>
    			<td><input type="button" value="+" onClick="AddRow()" ></td>
    		</tr>
    		<tr>
    			<td><input name="qty" type="text" size="2" /></td>
    			<td><input name="unit" type="text" size="2" /></td>
    			<td><input name="item" type="text" size="2" /></td>
    		</tr>
     
    	  </table>
    	  <table id="step">
    	  	<tr>
    			<td>step</td>
    			<td>description</td>
    			<td>+</td>
    		</tr>
    		<tr>
    			<td><input name="stepnum" type="text" size="2" /></td>
    			<td><textarea name="steptext" cols="" rows=""></textarea></td>
     
    	  </table>
    	  <table id="complement">
    	  	<tr>
    			<td>calories</td>
    			<td><input name="calories" type="text" /></td>
    		</tr>
    		<tr>
    			<td>total fat</td>
    			<td><input name="totalfat" type="text" /></td>
    		</tr>
    		<tr>
    			<td>cholesterol</td>
    			<td><input name="cholesterol" type="text" /></td>
    		</tr>
    		<tr>
    			<td>sodium</td>
    			<td><input name="sodium" type="text" /></td>
    		</tr>
    		<tr>
    			<td>carbohydrates</td>
    			<td><input name="carbohydrates" type="text" /></td>
    		</tr>
    		<tr>
    			<td>fiber</td>
    			<td><input name="fiber" type="text" /></td>
    		</tr>
     
    		<tr>
    			<td>protein</td>
    			<td><input name="protein" type="text" /></td>
    		</tr>
    		</table>
    		</td>
    	</tr>
    	<tr>
    		<td><input name="ok" type="submit" value="ok" /></td>
    	</tr>
    </table>
    </form>
     
    </body>
    </html>
    et ici ma page sql
    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
    <!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>Document sans titre</title>
    </head>
     
    <body>
    <?php
    require("params.inc.php");
    mysql_connect($hote, $login, $mdp); // Connexion à MySQL
    mysql_select_db($bd); // Sélection de la base
     
    //etape1: on insere les valeurs dans la table recette
    $ptitle = $_POST['title'];
    $pdescription = $_POST['description'];
    $pyld = $_POST['yld'];
    $ptime = $_POST['ptime'];
    $pctime = $_POST['ctime'];
    $pttime = $_POST['ttime'];
    $pcuisine = $_POST['cuisine'];
    $pconvenience = $_POST['convenience'];
    $poccasion = $_POST['occasion'];
    $pcourse = $_POST['course'];
     
     
     
    mysql_query("INSERT INTO recette VALUES('','$ptitle','$pdescription','$pyld','','','','','','','')") or die('Erreur SQL !<br>'.mysql_error());
     
    //on recup l'id de la recette
    $id_recette=mysql_insert_id();
     
    //etape2:on insere les valeures dans la table nutrients
    mysql_query("INSERT INTO nutrients VALUES('','$id_recette','$pcalories','$ptotalfat','','','','','')") or die('Erreur SQL !<br>'.mysql_error());
     
     
    $pcalories = $_POST['calories'];
    $ptotalfat = $_POST['totalfat'];
     
     
    //etape3:on insere les donnees dans la table ingredients.
    $pqty = $_POST['qty'];
    $punit = $_POST['unit'];
    $pitem = $_POST['item'];
     
     
    mysql_close(); // Déconnexion de MySQL
    ?>
    </body>
    </html>
    merci bcp pour votre aide..

  7. #7
    Membre averti
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 60
    Par défaut
    jai effectue qq modif, qui me semblent assez logiques, mais ca bug..:s

    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
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
     
    <!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>Document sans nom</title>
    <script type="text/javascript">
    var index = 1
    function AddRow(){
        var newRow = document.getElementById('ingredients').insertRow(-1);
        var newCell = newRow.insertCell(0);
        newCell.innerHTML = '<input name="ingredient1_'+index+'" type="text" />';
        newCell = newRow.insertCell(1);
        newCell.innerHTML = '<input name="ingredient2_'+index+'" type="text" />';
    	newCell = newRow.insertCell(2);
        newCell.innerHTML = '<input name="ingredient3_'+index+'" type="text" />';
    index = index +1
    }
    </script>
    </head>
     
    <body>
    <form method="post" action="add.php">
    <table>
    	<tr>
    		<td><table id="recette">
    		<tr>
    		 	<td>title</td>
    			<td><input name="title" type="text" /></td>
    		</tr>
    		<tr>
    			<td>description</td>
    			<td><textarea name="description" cols="" rows=""></textarea></td>
    		</tr>
    			<tr>
    		 	<td>yld</td>
    			<td><input name="yld" type="text" /></td>
    		</tr>
    		<tr>
    			<td>ptime</td>
    			<td><input name="ptime" type="text" /></td>
    		</tr>
    			<tr>
    		 	<td>ctime</td>
    			<td><input name="ctime" type="text" /></td>
    		</tr>
    		<tr>
    			<td>ttime</td>
    			<td><input name="ttime" type="text" /></td>
    		</tr>
    		<tr>
    		 	<td>cuisine</td>
    			<td><input name="cuisine" type="text" /></td>
    		</tr>
    		<tr>
    			<td>convenience</td>
    			<td><input name="convenience" type="text" /></td>
    		</tr>
    		<tr>
    			<td>occasion</td>
    			<td><input name="occasion" type="text" /></td>
    		</tr>
    		<tr>
    			<td>course</td>
    			<td><input name="course" type="text" /></td>
    		</tr>
     
     
    	  </table>
    	  </td>
     
    		<td> 
    		<table id="ingredients">
    	  	<tr>
    			<td>qty</td>
    			<td>unit</td>
    			<td>item</td>
    			<td><input type="button" value="+" onClick="AddRow()" ></td>
    		</tr>
    		<tr>
    			<td><input name="qty" type="text" size="2" /></td>
    			<td><input name="unit" type="text" size="2" /></td>
    			<td><input name="item" type="text" size="2" /></td>
    		</tr>
     
    	  </table>
    	  <table id="step">
    	  	<tr>
    			<td>step</td>
    			<td>description</td>
    			<td>+</td>
    		</tr>
    		<tr>
    			<td><input name="stepnum" type="text" size="2" /></td>
    			<td><textarea name="steptext" cols="" rows=""></textarea></td>
     
    	  </table>
    	  <table id="complement">
    	  	<tr>
    			<td>calories</td>
    			<td><input name="calories" type="text" /></td>
    		</tr>
    		<tr>
    			<td>total fat</td>
    			<td><input name="totalfat" type="text" /></td>
    		</tr>
    		<tr>
    			<td>cholesterol</td>
    			<td><input name="cholesterol" type="text" /></td>
    		</tr>
    		<tr>
    			<td>sodium</td>
    			<td><input name="sodium" type="text" /></td>
    		</tr>
    		<tr>
    			<td>carbohydrates</td>
    			<td><input name="carbohydrates" type="text" /></td>
    		</tr>
    		<tr>
    			<td>fiber</td>
    			<td><input name="fiber" type="text" /></td>
    		</tr>
     
    		<tr>
    			<td>protein</td>
    			<td><input name="protein" type="text" /></td>
    		</tr>
    		</table>
    		</td>
    	</tr>
    	<tr>
    		<td><input name="ok" type="submit" value="ok" /></td>
    	</tr>
    </table>
    </form>
     
    </body>
    </html>
    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
    <!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>Document sans titre</title>
    </head>
     
    <body>
    <?php
    require("params.inc.php");
    mysql_connect($hote, $login, $mdp); // Connexion à MySQL
    mysql_select_db($bd); // Sélection de la base
     
    //etape1: on insere les valeurs dans la table recette
    $ptitle = $_POST['title'];
    $pdescription = $_POST['description'];
    $pyld = $_POST['yld'];
    $ptime = $_POST['ptime'];
    $pctime = $_POST['ctime'];
    $pttime = $_POST['ttime'];
    $pcuisine = $_POST['cuisine'];
    $pconvenience = $_POST['convenience'];
    $poccasion = $_POST['occasion'];
    $pcourse = $_POST['course'];
     
     
     
    mysql_query("INSERT INTO recette VALUES('','$ptitle','$pdescription','$pyld','','','','','','','')") or die('Erreur SQL !<br>'.mysql_error());
     
    //on recup l'id de la recette
    $id_recette=mysql_insert_id();
     
    //etape2:on insere les valeures dans la table nutrients
    mysql_query("INSERT INTO nutrients VALUES('','$id_recette','$pcalories','$ptotalfat','','','','','')") or die('Erreur SQL !<br>'.mysql_error());
     
     
    $pcalories = $_POST['calories'];
    $ptotalfat = $_POST['totalfat'];
     
     
    //etape3:on insere les donnees dans la table ingredients.
     
     
    for(i=1;isset($_REQUEST['ingredient_'.i]);i++)
    {
    $pingredient1_ = $_POST['ingredient1_'.i];
    $pingredient2_ = $_POST['ingredient2_'.i];
    $pingredient3_ = $_POST['ingredient3_'.i];
       mysql_query("INSERT INTO ingredients VALUES('','$id_recette','$pingredient1_','$pingredient2_','$pingredient3_')") or die('Erreur SQL !<br>'.mysql_error());
     
    }
     
     
    mysql_close(); // Déconnexion de MySQL
    ?>
    </body>
    </html>

  8. #8
    Membre Expert Avatar de Djakisback
    Profil pro
    Inscrit en
    Février 2005
    Messages
    2 023
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 2 023
    Par défaut
    Salut,
    le mieux serait de changer la structure des tes tables car là tu vas stocker plein de fois les mêmes infos, mais bon...

    Pour tes champs ingrédients tu peux renommer tes input :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    <input type="text" name="ingredients[]">
    <input type="text" name="qyt[]">
    <input type="text" name="unit[]">
    Comme ca tu peux récupérer les infos dans $_POST['ingredients']

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    $c = count($_POST['ingredients']);
    for($i =0; $i <= $c; $i++) {
    mysql_query("INSERT INTO ingredients VALUES('','$id_recette','$pingredient1_','$nomIngredient', '".$_POST['qty'][$i]."', '".$_POST['unit'][$i]."')") or die('Erreur SQL !<br>'.mysql_error());
    }
    En ajoutant des tests en debut de page pour savoir si les POST sont vides ou non. D'autre part il faut que tu utilises mysql_real_escape_string() pour te protéger des injections sql.

    Bye

  9. #9
    Membre averti
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 60
    Par défaut
    marche pa ca..:s
    puis je crois que c'est sensiblement ce que jai fais dans la derniere version non?

  10. #10
    Membre averti
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 60
    Par défaut
    premiere question est ce que mes champs de texte de ma table ingredients doivent avoir le meme nom que ceux dans le javascript?

  11. #11
    Membre averti
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 60
    Par défaut
    hop jai simplifie le code...
    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
    <!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>Document sans titre</title>
    <script type="text/javascript">
    var index = 1
    function AddRow(){
        var newRow = document.getElementById('ingredients').insertRow(-1);
        var newCell = newRow.insertCell(0);
        newCell.innerHTML = '<input name="ingredient1_'+index+'" type="text" />';
        newCell = newRow.insertCell(1);
        newCell.innerHTML = '<input name="ingredient2_'+index+'" type="text" />';
    	newCell = newRow.insertCell(2);
        newCell.innerHTML = '<input name="ingredient3_'+index+'" type="text" />';
    index = index +1
    }
    </script>
    </head>
     
    <body><form method="post" action="addessai.php">
    <table id="ingredients">
    	  	<tr>
    			<td>qty</td>
    			<td>unit</td>
    			<td>item</td>
    			<td><input type="button" value="+" onClick="AddRow()" ></td>
    		</tr>
    		<tr>
    			<td><input name="qty" type="text" size="2" /></td>
    			<td><input name="unit" type="text" size="2" /></td>
    			<td><input name="item" type="text" size="2" /></td>
    		</tr>
     
    	  </table>
    	  <input name="ok" type="submit" value="ok" />
    	  </form>
    </body>
    </html>
    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
    <!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>Document sans titre</title>
    </head>
     
    <body>
    <?php
    require("params.inc.php");
    mysql_connect($hote, $login, $mdp); // Connexion à MySQL
    mysql_select_db($bd); // Sélection de la base
     
    //etape1: on insere les valeurs dans la table recette
    $ptitle = $_POST['title'];
    $pdescription = $_POST['description'];
    $pyld = $_POST['yld'];
    $ptime = $_POST['ptime'];
    $pctime = $_POST['ctime'];
    $pttime = $_POST['ttime'];
    $pcuisine = $_POST['cuisine'];
    $pconvenience = $_POST['convenience'];
    $poccasion = $_POST['occasion'];
    $pcourse = $_POST['course'];
     
     
     
    mysql_query("INSERT INTO recette VALUES('','$ptitle','$pdescription','$pyld','','','','','','','')") or die('Erreur SQL !<br>'.mysql_error());
     
    //on recup l'id de la recette
    $id_recette=mysql_insert_id();
     
    //etape2:on insere les valeures dans la table nutrients
    mysql_query("INSERT INTO nutrients VALUES('','$id_recette','$pcalories','$ptotalfat','','','','','')") or die('Erreur SQL !<br>'.mysql_error());
     
     
    $pcalories = $_POST['calories'];
    $ptotalfat = $_POST['totalfat'];
     
     
    //etape3:on insere les donnees dans la table ingredients.
     
     
    for(i=1;isset($_REQUEST['ingredient_'.i]);i++)
    {
    $pingredient1_.i = $_POST['ingredient1_'.i];
    $pingredient2_.i = $_POST['ingredient2_'.i];
    $pingredient3_.i = $_POST['ingredient3_'.i];
     
     
    echo $pingredients1_i;
     
    mysql_query("INSERT INTO ingredients VALUES('','$id_recette','$pingredient1_','$pingredient2_','$pingredient3_')") or die('Erreur SQL !<br>'.mysql_error());
     
    }
     
     
    mysql_close(); // Déconnexion de MySQL
    ?>
    </body>
    </html>

    jai essayde tester en placant un echo ca passe pas..:s

Discussions similaires

  1. Réponses: 2
    Dernier message: 11/08/2002, 21h27
  2. Divers questions
    Par Freakazoid dans le forum DirectX
    Réponses: 2
    Dernier message: 06/08/2002, 21h57
  3. question sur les message box !
    Par krown dans le forum Langage
    Réponses: 7
    Dernier message: 02/08/2002, 16h11
  4. Question de faisabilité
    Par lisarasu dans le forum CORBA
    Réponses: 3
    Dernier message: 14/05/2002, 11h26
  5. [HyperFile] 2 questions de débutant
    Par khan dans le forum HyperFileSQL
    Réponses: 2
    Dernier message: 29/04/2002, 23h18

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