2017-02-13 1 views
1

Ich habe einige Probleme beim Einfügen von Daten in der Datenbank, Werte werden zwischen zwei Zeilen gemischt. Ich habe versucht, eine einzige while-Schleife zu machen, aber selbst das funktioniert nicht, also werde ich meinen Code so einfügen, wie er am Anfang war. Irgendwelche Ratschläge oder Lösungen sind willkommen, es wird großartig. Hier ist das Echo, dass ich auf die beiden einfügen Abfrage nach dem Einfügen von Test in Textareas für Kommentare Boxen:Einfügen von Daten in der Datenbank MYSQL, Daten werden gemischt

Choix beziehen sich auf Radiobutton Werte und Kommentare zu Werten von Kommentaren Boxen (Textarea).

INSERT INTO questionnaire(Choix,Commentara) VALUES('test1','test1') 
INSERT INTO questionnaire(Choix,Commentara) VALUES('test2','test2') 
INSERT INTO questionnaire(Choix,Commentara) VALUES('test3','test3') 
INSERT INTO questionnaire(Choix,Commentara) VALUES('test4','test4') 

PS: Ich verwende Navicat für MYSQL und ich bin noch neu auf PHP, so bitte nehmen Sie sich Zeit zu erklären.

Mit freundlichen Grüßen A.V. Hier

<?php 
$link=Mysqli_connect($host,$login,$pass,$dbname); 
$un = 0; 
$kv = 0 ; 
$msgerror = "Veuillez remplir tous les champs ";  

if(isset($_POST["bouton10"])){ 



    $id = !empty($_REQUEST["Picolo4"]) ? $_REQUEST["Picolo4"] : ""; 
    $Nom = !empty($_REQUEST["Picolo1"]) ? $_REQUEST["Picolo1"] : ""; 
    $Prenom = !empty($_REQUEST["Picolo2"]) ? $_REQUEST["Picolo2"] : ""; 
    $Email = !empty($_REQUEST["Picolo3"]) ? $_REQUEST["Picolo3"] : ""; 
    $RefClient = !empty($_REQUEST["Picolo5"]) ? $_REQUEST["Picolo5"] : ""; 
    if ($id !="" && $Nom !="" && $Prenom !="" && $Email !="" && $RefClient !=""){ 

     $recherche= "SELECT Ref,Question,Choix,Commentara FROM questionnaire WHERE Qref ='$id'"; 


     mysqli_query($link,$recherche); 





     $result= mysqli_query($link,$recherche); 
     $num_results = $result->num_rows; 
     while ($row = mysqli_fetch_assoc($result)) { 

      $Ref =$row["Ref"]; 
      $Question  =$row["Question"]; 

      $un++; 
      $kv++; 

      echo" <tr bgcolor=\"white\"> 

      <td>$Question </td> 
      <td> 
       3<input type=\"radio\" name =\"$un\" id =\"un\" value = \"3\"> 
       2<input type=\"radio\" name =\"$un\" id =\"un\" value = \"2\"> 
       1<input type=\"radio\" name =\"$un\" id =\"un\" value = \"1\"> 
       0<input type=\"radio\" name =\"$un\" id =\"un\" value = \"0\"> 
       PA<input type=\"radio\" name =\"$un\" id =\"un\" value = \"PA\"> 
      </td> 
      <td width = \"60\"> <textarea name =\"$kv\" id =\"kv\" rows=\"5\" placeholder=\"Votre commentaire\"></textarea> </td> 
     </tr> 


    </div> 
</div> 
"; 

} 
} 
else { 

    echo "<script type='text/javascript'>alert('$msgerror')</script>"; 

} 
} 

$kv = 1; 
$un = 1; 
$i= 1 ; 

if (isset($_POST["bouton11"])) { 





    while(isset($_POST[$un])||(isset($_POST[$kv]))){ 
     $choix = $_POST["$un"]; 
     $comment = $_POST["$kv"]; 


     $enregistrer = "INSERT INTO questionnaire(Choix,Commentara) VALUES('$choix','$comment') "; 

     $un++; 
     $kv++; 
     $i++; 
     echo"$enregistrer"; 
     mysqli_query($link, $enregistrer); 

    } 
//Besoin d'un correctif 

    //while(isset($_POST[$kv])) { 
    // $comment = $_POST["$kv"]; 


    // $enregistrer2 = "INSERT INTO questionnaire(Commentara) VALUES('$comment')"; 
     // $kv++; 

    // echo"$enregistrer2"; 

    // mysqli_query($link, $enregistrer2); 
    //} 

} 



?> 

ist die Form:

<DOCTYPE HTML> 
    <HTML> 
     <HEAD> 
     <TITLE>Foredeck_Testeur</TITLE> 
     <meta name="viewport" content="width=device-width, initial-scale=1" charset="utf-8"> 
     <meta http-equiv="X-UA-Compatible" content="IE=edge"/> 
     <link href="css/bootstrap.min.css" type="text/css" rel="stylesheet"> 

     <link rel="stylesheet" href="css/footer-distributed-with-address-and-phones.css"> 
     <link rel="stylesheet" href="css/tab.css"> 
     <link href="http://fonts.googleapis.com/css?family=Cookie" rel="stylesheet" type="text/css"> 
     <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/angular_material/1.1.0/angular-material.min.css"> 

     <script type="text/javascript" src="jquery/jquery-1.11.3.min.js"></script> 
     <script type="text/javascript" src="js/tab.js"></script> 


     <style type="text/css"> 
      .footer { 
       min-width: 100%; 
       height: auto; 
       text-align: center; 
       background: rgb(0, 0, 0); 
       position: fixed; 
       bottom: 0%; 
       margin-top: 50%; 
      } 

      .wrapper { 
       min-height: 100%; 
       height: auto !important; 
       height: 100%; 
       margin: 0 auto -142px; /* the bottom margin is the negative value of the footer's height */ 
      } 




     </STYLE> 


    </HEAD> 


    <BODY bgcolor="#6495ED"> 
     <form method ="post" id=""> 

     <table class="center-table" border ="1" align="center" > 

      <tr bgcolor="#b0bffc"> 
       <td>Nom:</TD><TD><input type="text" class="form-control" name ="Picolo1" id="Picolo1" > </textarea></td><td><P>(Obligatoire*)</P></td> 




      </tr> 
      <tr bgcolor="#b0bffc"> 
       <td>Prénom:</TD><TD><input type="text" class="form-control" name ="Picolo2" id="Picolo2"> </textarea></td><td><P>(Obligatoire*)</P></td> 
      </tr> 
      <tr bgcolor="#b0bffc"> 
       <td>Email:</TD><TD><input type="mail" class="form-control" name ="Picolo3" id="Picolo3"> </textarea></td><td><P>(Obligatoire*)</P></td> 
      </tr> 

      <tr bgcolor="#b0bffc"> 
       <td>Référence Questionnaire:</td> 
       <td><input type="text" class="form-control" name ="Picolo4" id="Picolo4" > </textarea></td> <td> (Obligatoire*)</td> 
      </tr> 
      <tr bgcolor="#b0bffc"> 
       <td>Référence Client:</td> 
       <td><input type="text" class="form-control" name ="Picolo5" id="Picolo5" > </textarea></td> <td> (Obligatoire*)</td> 
      </tr> 
      <Tr> 
       <TD bgcolor="#b0bffc"> 
        <Center><button type="submit" name="bouton10" id="bouton10" class="btn btn-default" >Confirmer</button></Center> 
       </TD> 
      </TR> 
     </table> 
     <BR> 

      <table class="center-table" border ="1" align="center" > 

       <tr bgcolor="#b0bffc"> <td> Question</td> <td>Choix</td> <td>Commentaires</td> </tr> 

       <?php 
       include("bdconnect_Foredeck.php"); 
       include("foredeckaffiche_client.php"); 
       include("foredeck_insert_client.php"); 

       ?> 

      </Table> 
      <BR> 


       <Center><button type="submit" name="bouton11" id="bouton11" class="btn btn-default" >Enregistrer</button></Center> 
       <BR> 
       <BR> 
       <Center> 
        <a href ="Foredeckmain.php" >Retour</button> </a> 


       </Center> 
      </form> 
     </div> 
     <div class="footer"> 
      <p> 
       <font color="white"> Foredeck Consulting Ltd &copy; 2017 </font> 
      </p> 
     </div> 
    </BODY> 
    </HTML> 
+0

Wie soll es eingefügt werden? – affaz

+0

So: ein Wert, nach dem Radio-Button des Radio-Button-Set ausgewählt und dann der Kommentar. –

+0

Sie müssen sagen, was in der Datenbank –

Antwort

-1

Wenn Sie sowohl radiobutton und textarea auf derselben Zeile eingefügt werden soll, ist dies, wie Sie tun sollten. Beide Felder sollten aus einer einzigen Einfügeabfrage eingefügt werden

if (isset($_POST["bouton11"])) 
{ 

$choix = $_POST["$un"]; 
$comment = $_POST["$kv"]; 
$enregistrer = INSERT INTO questionnaire(Choix,Commentara) VALUES($choix,$comment); 
mysqli_query($link, $enregistrer); 

} 
+0

Es gibt ein Problem, es ist nur für einen Einsatz, ich habe eine Menge Frage in meiner Umfrage. –

+0

Ich werde meinen Beitrag entsprechend Ihrer Antwort bearbeiten, nehmen Sie bitte eine Beute. –

+0

sicher ... il gucken – affaz

1

Es ist in Ordnung, ich habe es!

<?php 
$link=Mysqli_connect($host,$login,$pass,$dbname); 
$un = 0; 
$kv = 0 ; 
$msgerror = "Veuillez remplir tous les champs ";  

if(isset($_POST["bouton10"])){ 



    $id = !empty($_REQUEST["Picolo4"]) ? $_REQUEST["Picolo4"] : ""; 
    $Nom = !empty($_REQUEST["Picolo1"]) ? $_REQUEST["Picolo1"] : ""; 
    $Prenom = !empty($_REQUEST["Picolo2"]) ? $_REQUEST["Picolo2"] : ""; 
    $Email = !empty($_REQUEST["Picolo3"]) ? $_REQUEST["Picolo3"] : ""; 
    $RefClient = !empty($_REQUEST["Picolo5"]) ? $_REQUEST["Picolo5"] : ""; 
    if ($id !="" && $Nom !="" && $Prenom !="" && $Email !="" && $RefClient !=""){ 

     $recherche= "SELECT Ref,Question,Choix,Commentara FROM questionnaire WHERE Qref ='$id'"; 


     mysqli_query($link,$recherche); 





     $result= mysqli_query($link,$recherche); 
     $num_results = $result->num_rows; 
     while ($row = mysqli_fetch_assoc($result)) { 

      $Ref =$row["Ref"]; 
      $Question  =$row["Question"]; 

      $un++; 
      $kv++; 

      echo" <tr bgcolor=\"white\"> 

      <td>$Question </td> 
      <td> 
       3<input type=\"radio\" name =\"$un\" id =\"un1\" value = \"3\"> 
       2<input type=\"radio\" name =\"$un\" id =\"un2\" value = \"2\"> 
       1<input type=\"radio\" name =\"$un\" id =\"un3\" value = \"1\"> 
       0<input type=\"radio\" name =\"$un\" id =\"un4\" value = \"0\"> 
       PA<input type=\"radio\" name =\"$un\" id =\"un5\" value = \"PA\"> 
      </td> 
      <td width = \"60\"> <textarea name =\"text_$kv\" id =\"kv\" rows=\"5\" placeholder=\"Votre commentaire\"></textarea> </td> 
     </tr> 


    </div> 
</div> 
"; 

} 
} 
else { 

    echo "<script type='text/javascript'>alert('$msgerror')</script>"; 

} 
} 

$kv = 1; 
$un = 1; 
$i= 1 ; 

if (isset($_POST["bouton11"])) { 






while((isset($_POST[$kv]))||(isset($_POST[$un]))){ 
$comment = $_POST["text_$kv"]; 
$choix=$_POST["$un"]; 

$enregistrer = "INSERT INTO questionnaire(Choix,Commentara) VALUES('$choix','$comment') "; 
$kv++; 
$un++; 
echo "$comment"; 
$i++; 
echo"$choix"; 
echo"$enregistrer"; 
mysqli_query($link, $enregistrer); 

} 
//Besoin d'un correctif 

    //while(isset($_POST[$kv])) { 
    // $comment = $_POST["$kv"]; 


    // $enregistrer2 = "INSERT INTO questionnaire(Commentara) VALUES('$comment')"; 
     // $kv++; 

    // echo"$enregistrer2"; 

    // mysqli_query($link, $enregistrer2); 
    //} 

} 



?>