Ankündigung

Einklappen
Keine Ankündigung bisher.

Vereinfachung eines POST-Formulars mit Eintragung in Datenbank

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Vereinfachung eines POST-Formulars mit Eintragung in Datenbank

    Guten Morgen/Abend!

    Mein Name ist Dominic Resch und ich bin zurzeit dafür zuständig für unsere Community eine Seite zu designen bzw. funktionstüchtig zu machen.
    Es gibt ein Backend-Bereich in dem man, sofern man eingeloggt ist, verschiedene Werte einstellen bzw. aktualisieren kann. Unter anderem gibt es die Seite "Eigene Seite", in der das eingeloggte Mitglied seine Rechnerkonfiguration ändern kann.
    Auf dieser Seite gibt es ein Formular mit ca 34 Textfeldern. Diese werden nach dem Druck auf den "Aktualisieren" Button, in die MySQL-Datenbank über PDO geschrieben.
    Das Problem ist, das ich jedes einzelne Textfeld in eine eigene Variable gespeichert hab (z.B. Gehäuse in case, zusätzlicher Lüfter in additional_fan, usw.).
    In der MySQL-Funktion die dafür zuständig ist, dass die Variablen in die Datenbank eingetragen werden, hat die Variablennamen mit einem : davor drinnen (z.B. case=:case, additional_fan=:additional_fan, usw.), welche dann mit den Variablen, über $stmt->bindParam(":case", $case);, befüllt werden.

    Ist es nun möglich das ganze zu vereinfachen? Das man alles in eine Variable quasi speichert und dann nur die eine Variable in der MySQL Funktion notwendig ist, um alle Felder zu füllen? Ich habe mir überlegt ein Array herzunehmen, allerdings werde ich für dieses vermutlich eine while-Schleife brauchen. ALlerdings habe ich nei mit Arrays bzw. der while-Schleife gearbeitet. Nun wollte ich halt fragen:

    Ist es mit einem Array einfacher? Brauche ich dann die while-Schleife? Oder gibt es generell ne einfache alternative dazu?

    Mit freundlichen Grüßen

    Dominic Resch

  • #2
    Arrays in Datenbanken in Form von "a, b, c" sind nie günstig.

    Wenn du also aus den Textfeldern per $_POST die Felder ausliest, kannst du das doch auch so eintragen:

    INSERT INTO `tabelle` SET `spalte1` = " . $_POST["erste"] . ", `spalte2` = ...

    Kommentar


    • #3
      Keine Ahnung ob du's so meinst: http://www.php.de/datenbanken/112365...tml#post827325 ohne bindParam though
      [COLOR=#A9A9A9]Relax, you're doing fine.[/COLOR]
      [URL="http://php.net/"]RTFM[/URL] | [URL="http://php-de.github.io/"]php.de Wissenssammlung[/URL] | [URL="http://use-the-index-luke.com/de"]Datenbankindizes[/URL] | [URL="https://www.php.de/forum/webentwicklung/datenbanken/111631-bild-aus-datenbank-auslesen?p=1209079#post1209079"]Dateien in der DB?[/URL]

      Kommentar


      • #4
        Ungetestet, aber so ähnlich sollte es gehen. Ob das jetzt eine Vereinfachung ist, wenn du sowieso die Spalten kennst, wage ich aber zu bezweifeln.

        PHP-Code:

        <?php
        $tableColumns 
        = array("case""additional_fan");

        $sql "UPDATE rechnerkonfiguration SET ";

        foreach(
        $tableColumns as $columnName) {
            
        $sql .= $columnName."=:".$columnName.",";
        }

        $sql trim($sql',');

        $sql .= ' WHERE 1=2';

        $stmt $dbh->prepare($sql);

        foreach(
        $tableColumns as $columnName) {
            
        $value '';
            if(isset(
        $_POST[$columnName])) {
                
        $value $_POST[$columnName];
            }
            
        $stmt->bindParam(':'.$columnName$value);
        }

        $stmt->execute();
        Tutorials zum Thema Technik:
        https://pilabor.com
        https://www.fynder.de

        Kommentar


        • #5
          Ansonsten kannst du uns gerne etwas Code zeigen, dann können wir weiter sehen, was sich da so machen lässt.

          Kommentar


          • #6
            Ließen sich nicht theoretisch die Textfelder im HTML Formular durch namens Änderung zu einem
            PHP-Code:
            $_POST['hardware_array'
            zusammenfassen. Du hättest also nur ein Post Array mit einer festgelegten Variablen rheinfolge. Dann könntest du im PHP Script die :case etc. Platzhalter in der prepare Anweisung durch simple ? ersetzen.
            Im Ergebnis würdest du dann also nur ein
            PHP-Code:
            execute($_POST['Hardware_array']) 
            ausführen und alle Werte würden an der richtigen Stelle landen.

            Kommentar


            • #7
              Guten Abend!
              Sorry Leute, hatte die letzten Tage einiges zutun, weshalb ich leider nicht reinschneien konnte.

              Jedenfalls schonmal ein großes Dankeschön für eure Antworten, testen kann ich diese allerdings erst in den nächsten Tagen.
              Allerdings wurde ich ja nach dem Code gefragt, den ich hier natürlich einfügen kann:

              Datenbank-Aufbau läuft über PDO:
              PHP-Code:
              class DB{
                  private static 
              $_db_host="localhost";
                  private static 
              $_db_name="fungamearea_de_neu_";
                  private static 
              $_db_username="fungamearea";
                  private static 
              $_db_password="D123456d";
                  private static 
              $_db;
                  function 
              __construct(){
                      try{
                          
              self::$_db=new PDO("mysql:host=".self::$_db_host.";dbname=".self::$_db_name,self::$_db_username,self::$_db_password);
                      }catch(
              PDOException $e){
                          echo 
              "Datenbankverbindung gescheitert!";
                          die();    
                      }
                  } 
              Funktion in mysql.php
              PHP-Code:
              function editMemberSite($about$pc_case$additional_fan$additional_fan_2$additional_fan_3$additional_ds$additional_ds_2$additional_ds_3$power_supply$motherboard$cpu$cpu_fan$memory$graphic_card$graphic_card_2$main_hd$additional_hd$additional_hd_2$additional_hd_3$additional_hd_4$additional_hd_5$additional_hd_6$monitor$monitor_2$monitor_3$monitor_4$keyboard$mouse$headset$microphone$microphone_boom$microphone_pop_filter$operating_system$recording_program_video$recording_program_audio$render_program){
                      
              $stmt=self::$_db->prepare("UPDATE users SET about=:about, pc_case=:pc_case, additional_fan=:additional_fan, additional_fan_2=:additional_fan_2, additional_fan_3=:additional_fan_3, additional_ds=:additional_ds, additional_ds_2=:additional_ds_2, additional_ds_3=:additional_ds_3, power_supply=:power_supply, motherboard=:motherboard, cpu=:cpu, cpu_fan=:cpu_fan, memory=:memory, graphic_card=:graphic_card, graphic_card_2=:graphic_card_2, main_hd=:main_hd, additional_hd=:additional_hd, additional_hd_2=:additional_hd_2, additional_hd_3=:additional_hd_3, additional_hd_4=:additional_hd_4, additional_hd_5=:additional_hd_5, additional_hd_6=:additional_hd_6, monitor=:monitor, monitor_2=:monitor_2, monitor_3=:monitor_3, monitor_4=:monitor_4, keyboard=:keyboard, mouse=:mouse, headset=:headset, microphone=:microphone, microphone_boom=:microphone_boom, microphone_pop_filter=:microphone_pop_filter, operating_system=:operating_system, recording_program_video=:recording_program_video, recording_program_audio=:recording_program_audio, render_program=:render_program WHERE session=:sid");
                      
              $stmt->bindParam(":about"$about);
                      
              $stmt->bindParam(":pc_case"$pc_case);
                      
              $stmt->bindParam(":additional_fan"$additional_fan);
                      
              $stmt->bindParam(":additional_fan_2"$additional_fan_2);
                      
              $stmt->bindParam(":additional_fan_3"$additional_fan_3);
                      
              $stmt->bindParam(":additional_ds"$additional_ds);
                      
              $stmt->bindParam(":additional_ds_2"$additional_ds_2);
                      
              $stmt->bindParam(":additional_ds_3"$additional_ds_3);
                      
              $stmt->bindParam(":power_supply"$power_supply);
                      
              $stmt->bindParam(":motherboard"$motherboard);
                      
              $stmt->bindParam(":cpu"$cpu);
                      
              $stmt->bindParam(":cpu_fan"$cpu_fan);
                      
              $stmt->bindParam(":memory"$memory);
                      
              $stmt->bindParam(":graphic_card"$graphic_card);
                      
              $stmt->bindParam(":graphic_card_2"$graphic_card_2);
                      
              $stmt->bindParam(":main_hd"$main_hd);
                      
              $stmt->bindParam(":additional_hd"$additional_hd);
                      
              $stmt->bindParam(":additional_hd_2"$additional_hd_2);
                      
              $stmt->bindParam(":additional_hd_3"$additional_hd_3);
                      
              $stmt->bindParam(":additional_hd_4"$additional_hd_4);
                      
              $stmt->bindParam(":additional_hd_5"$additional_hd_5);
                      
              $stmt->bindParam(":additional_hd_6"$additional_hd_6);
                      
              $stmt->bindParam(":monitor"$monitor);
                      
              $stmt->bindParam(":monitor_2"$monitor_2);
                      
              $stmt->bindParam(":monitor_3"$monitor_3);
                      
              $stmt->bindParam(":monitor_4"$monitor_4);
                      
              $stmt->bindParam(":keyboard"$keyboard);
                      
              $stmt->bindParam(":mouse"$mouse);
                      
              $stmt->bindParam(":headset"$headset);
                      
              $stmt->bindParam(":microphone"$microphone);
                      
              $stmt->bindParam(":microphone_boom"$microphone_boom);
                      
              $stmt->bindParam(":microphone_pop_filter"$microphone_pop_filter);
                      
              $stmt->bindParam(":operating_system"$operating_system);
                      
              $stmt->bindParam(":recording_program_video"$recording_program_video);
                      
              $stmt->bindParam(":recording_program_audio"$recording_program_audio);
                      
              $stmt->bindParam(":render_program"$render_program);
                      
              $stmt->bindParam(":sid"session_id());
                      if(
              $stmt->execute()){
                          return 
              true;
                      }else{
                          return 
              false;
                      }
                  } 
              member-site.php (Seite, wo die Einsellungen vorgenommen werden
              PHP-Code:
              <?php
              if(isset($_POST["updateMemberSite"])){
                  
              $about=$_POST["about"];
                  
              $pc_case=$_POST["pc_case"];
                  
              $additional_fan=$_POST["additional_fan"];
                  
              $additional_fan_2=$_POST["additional_fan_2"];
                  
              $additional_fan_3=$_POST["additional_fan_3"];
                  
              $additional_ds=$_POST["additional_ds"];
                  
              $additional_ds_2=$_POST["additional_ds_2"];
                  
              $additional_ds_3=$_POST["additional_ds_3"];
                  
              $power_supply=$_POST["power_supply"];
                  
              $motherboard=$_POST["motherboard"];
                  
              $cpu=$_POST["cpu"];
                  
              $cpu_fan=$_POST["cpu_fan"];
                  
              $memory=$_POST["memory"];
                  
              $graphic_card=$_POST["graphic_card"];
                  
              $graphic_card_2=$_POST["graphic_card_2"];
                  
              $main_hd=$_POST["main_hd"];
                  
              $additional_hd=$_POST["additional_hd"];
                  
              $additional_hd_2=$_POST["additional_hd_2"];
                  
              $additional_hd_3=$_POST["additional_hd_3"];
                  
              $additional_hd_4=$_POST["additional_hd_4"];
                  
              $additional_hd_5=$_POST["additional_hd_5"];
                  
              $additional_hd_6=$_POST["additional_hd_6"];
                  
              $monitor=$_POST["monitor"];
                  
              $monitor_2=$_POST["monitor_2"];
                  
              $monitor_3=$_POST["monitor_3"];
                  
              $monitor_4=$_POST["monitor_4"];
                  
              $keyboard=$_POST["keyboard"];
                  
              $mouse=$_POST["mouse"];
                  
              $headset=$_POST["headset"];
                  
              $microphone=$_POST["microphone"];
                  
              $microphone_boom=$_POST["microphone_boom"];
                  
              $microphone_pop_filter=$_POST["microphone_pop_filter"];
                  
              $operating_system=$_POST["operating_system"];
                  
              $recording_program_video=$_POST["recording_program_video"];
                  
              $recording_program_audio=$_POST["recording_program_audio"];
                  
              $render_program=$_POST["render_program"];
                  
              $editMemberSite=$db->editMemberSite($about$pc_case$additional_fan$additional_fan_2$additional_fan_3$additional_ds$additional_ds_2$additional_ds_3$power_supply$motherboard$cpu$cpu_fan$memory$graphic_card$graphic_card_2$main_hd$additional_hd$additional_hd_2$additional_hd_3$additional_hd_4$additional_hd_5$additional_hd_6$monitor$monitor_2$monitor_3$monitor_4$keyboard$mouse$headset$microphone$microphone_boom$microphone_pop_filter$operating_system$recording_program_video$recording_program_audio$render_program);
                  if(
              $editMemberSite){
                      
              ?><script>window.location="index.php?site=<?php echo $site;?>"</script><?php
                  
              }else{
                      
              ?><script>window.location="index.php?site=<?php echo $site;?>"</script><?php
                  
              }
              }
              $getUserBySession=$db->getUserBySession();
              foreach(
              $getUserBySession as $userInformation){
                  
              $about=$userInformation["about"];
                  
              $pc_case=$userInformation["pc_case"];
                  
              $additional_fan=$userInformation["additional_fan"];
                  
              $additional_fan_2=$userInformation["additional_fan_2"];
                  
              $additional_fan_3=$userInformation["additional_fan_3"];
                  
              $additional_ds=$userInformation["additional_ds"];
                  
              $additional_ds_2=$userInformation["additional_ds_2"];
                  
              $additional_ds_3=$userInformation["additional_ds_3"];
                  
              $power_supply=$userInformation["power_supply"];
                  
              $motherboard=$userInformation["motherboard"];
                  
              $cpu=$userInformation["cpu"];
                  
              $cpu_fan=$userInformation["cpu_fan"];
                  
              $memory=$userInformation["memory"];
                  
              $graphic_card=$userInformation["graphic_card"];
                  
              $graphic_card_2=$userInformation["graphic_card_2"];
                  
              $main_hd=$userInformation["main_hd"];
                  
              $additional_hd=$userInformation["additional_hd"];
                  
              $additional_hd_2=$userInformation["additional_hd_2"];
                  
              $additional_hd_3=$userInformation["additional_hd_3"];
                  
              $additional_hd_4=$userInformation["additional_hd_4"];
                  
              $additional_hd_5=$userInformation["additional_hd_5"];
                  
              $additional_hd_6=$userInformation["additional_hd_6"];
                  
              $monitor=$userInformation["monitor"];
                  
              $monitor_2=$userInformation["monitor_2"];
                  
              $monitor_3=$userInformation["monitor_3"];
                  
              $monitor_4=$userInformation["monitor_4"];
                  
              $keyboard=$userInformation["keyboard"];
                  
              $mouse=$userInformation["mouse"];
                  
              $headset=$userInformation["headset"];
                  
              $microphone=$userInformation["microphone"];
                  
              $microphone_boom=$userInformation["microphone_boom"];
                  
              $microphone_pop_filter=$userInformation["microphone_pop_filter"];
                  
              $operating_system=$userInformation["operating_system"];
                  
              $recording_program_video=$userInformation["recording_program_video"];
                  
              $recording_program_audio=$userInformation["recording_program_audio"];
                  
              $render_program=$userInformation["render_program"];
              }
              ?>
              <form action="index.php?site=<?php echo $site;?>" method="POST">
                  <h3 style='margin-top: 10px'>Über mich:</h3>
                  <hr style='margin-bottom: 6px'>
                  <textarea name="about" style="width: 550px; height: 200px"><?php echo $about;?></textarea>
                  <h3 style='margin-top: 10px'>Rechnerkonfiguration:</h3>
                  <h4 style='margin-top: 10px'>Gehäuse-Aufbau:</h4>
                  <hr style='margin-bottom: 6px'>
                  <table>
                      <tr>
                          <td style="width: 250px">Gehäuse:</td>
                          <td><input type="text" name="pc_case" value="<?php echo $pc_case;?>" style="width: 300px" required></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Zusätzlicher Lüfter:</td>
                          <td><input type="text" name="additional_fan" value="<?php echo $additional_fan;?>" style="width: 300px"></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Zusätzlicher Lüfter:</td>
                          <td><input type="text" name="additional_fan_2" value="<?php echo $additional_fan_2;?>" style="width: 300px"></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Zusätzlicher Lüfter:</td>
                          <td><input type="text" name="additional_fan_3" value="<?php echo $additional_fan_3;?>" style="width: 300px"></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Zusätzliche Dockingstation:</td>
                          <td><input type="text" name="additional_ds" value="<?php echo $additional_ds;?>" style="width: 300px"></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Zusätzliche Dockingstation:</td>
                          <td><input type="text" name="additional_ds_2" value="<?php echo $additional_ds_2;?>" style="width: 300px"></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Zusätzliche Dockingstation:</td>
                          <td><input type="text" name="additional_ds_3" value="<?php echo $additional_ds_3;?>" style="width: 300px"></td>
                      </tr>
                  </table>
                  <h4 style='margin-top: 10px'>Hardware:</h4>
                  <hr style='margin-bottom: 6px'>
                  <table>
                      <tr>
                          <td style="width: 250px">Netzteil:</td>
                          <td><input type="text" name="power_supply" value="<?php echo $power_supply;?>" style="width: 300px" required></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Motherboard:</td>
                          <td><input type="text" name="motherboard" value="<?php echo $motherboard;?>" style="width: 300px" required></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Prozessor:</td>
                          <td><input type="text" name="cpu" value="<?php echo $cpu;?>" style="width: 300px" required></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">CPU-Kühler:</td>
                          <td><input type="text" name="cpu_fan" value="<?php echo $cpu_fan;?>" style="width: 300px" required></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Arbeitsspeicher:</td>
                          <td><input type="text" name="memory" value="<?php echo $memory;?>" style="width: 300px" required></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Grafikkarte:</td>
                          <td><input type="text" name="graphic_card" value="<?php echo $graphic_card;?>" style="width: 300px" required></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">2. Grafikkarte:</td>
                          <td><input type="text" name="graphic_card_2" value="<?php echo $graphic_card_2;?>" style="width: 300px"></td>
                      </tr>
                  </table>
                  <h4 style='margin-top: 10px'>Festplatten:</h4>
                  <hr style='margin-bottom: 6px'>
                  <table>
                      <tr>
                          <td style="width: 250px">Hauptfestplatte:</td>
                          <td><input type="text" name="main_hd" value="<?php echo $main_hd;?>" style="width: 300px" required></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Zusätzlicher Speicher:</td>
                          <td><input type="text" name="additional_hd" value="<?php echo $additional_hd;?>" style="width: 300px"></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Zusätzlicher Speicher:</td>
                          <td><input type="text" name="additional_hd_2" value="<?php echo $additional_hd_2;?>" style="width: 300px"></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Zusätzlicher Speicher:</td>
                          <td><input type="text" name="additional_hd_3" value="<?php echo $additional_hd_3;?>" style="width: 300px"></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Zusätzlicher Speicher:</td>
                          <td><input type="text" name="additional_hd_4" value="<?php echo $additional_hd_4;?>" style="width: 300px"></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Zusätzlicher Speicher:</td>
                          <td><input type="text" name="additional_hd_5" value="<?php echo $additional_hd_5;?>" style="width: 300px"></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Zusätzlicher Speicher:</td>
                          <td><input type="text" name="additional_hd_6" value="<?php echo $additional_hd_6;?>" style="width: 300px"></td>
                      </tr>
                  </table>
                  <h4 style='margin-top: 10px'>Ein-/Ausgabegerät und Zubehör:</h4>
                  <hr style='margin-bottom: 6px'>
                  <table>
                      <tr>
                          <td style="width: 250px">Monitor:</td>
                          <td><input type="text" name="monitor" value="<?php echo $monitor;?>" style="width: 300px" required></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">2. Monitor:</td>
                          <td><input type="text" name="monitor_2" value="<?php echo $monitor_2;?>" style="width: 300px"></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">3. Monitor:</td>
                          <td><input type="text" name="monitor_3" value="<?php echo $monitor_3;?>" style="width: 300px"></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">4. Monitor:</td>
                          <td><input type="text" name="monitor_4" value="<?php echo $monitor_4;?>" style="width: 300px"></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Tastatur:</td>
                          <td><input type="text" name="keyboard" value="<?php echo $keyboard;?>" style="width: 300px" required></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Maus:</td>
                          <td><input type="text" name="mouse" value="<?php echo $mouse;?>" style="width: 300px" required></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Headset:</td>
                          <td><input type="text" name="headset" value="<?php echo $headset;?>" style="width: 300px"></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Mikrofon:</td>
                          <td><input type="text" name="microphone" value="<?php echo $microphone;?>" style="width: 300px"></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Mikrofonarm:</td>
                          <td><input type="text" name="microphone_boom" value="<?php echo $microphone_boom;?>" style="width: 300px"></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Mikrofon Pop-Schutz:</td>
                          <td><input type="text" name="microphone_pop_filter" value="<?php echo $microphone_pop_filter;?>" style="width: 300px"></td>
                      </tr>
                  </table>
                  <h4 style='margin-top: 10px'>Software:</h4>
                  <hr style='margin-bottom: 6px'>
                  <table>
                      <tr>
                          <td style="width: 250px">Betriebssystem:</td>
                          <td><input type="text" name="operating_system" value="<?php echo $operating_system;?>" style="width: 300px" required></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Aufnahmeprogramm (Video):</td>
                          <td><input type="text" name="recording_program_video" value="<?php echo $recording_program_video;?>" style="width: 300px" required></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Aufnahmeprogramm (Audio):</td>
                          <td><input type="text" name="recording_program_audio" value="<?php echo $recording_program_audio;?>" style="width: 300px" required></td>
                      </tr>
                      <tr>
                          <td style="width: 250px">Renderprogramm:</td>
                          <td><input type="text" name="render_program" value="<?php echo $render_program;?>" style="width: 300px" required></td>
                      </tr>
                      <tr>
                          <td></td>
                          <td style="float: right"><input type="submit" name="updateMemberSite" value="Aktualisieren"></td>
                      </tr>
                  </table>
              </form>
              WIe gesagt es is wirklich ne scheiß Arbeit gewesen, hoffe ihr versteht jetzt warum ich das vereinfachen will.. ^^

              Wenn ihr nun eine bessere Methode kennt, dann haut se her Ich schau mir derzeit, sobald ich dazu komm, die bisherigen Lösungen an!

              Mit freundlichen Grüßen

              Dominic Resch aka CaptTaifun

              Kommentar


              • #8
                Pack nicht alle Daten in eine Tabelle, das ist ja grauenhaft.

                Die Zusatzinfos kannst du besser in einer gesonderten Tabelle ablegen (Zeilenbasiert!)
                Über 90% aller Gewaltverbrechen passieren innerhalb von 24 Stunden nach dem Konsum von Brot.

                Kommentar


                • #9
                  Vielleicht solltest du auch nicht unbedingt die Logindaten für die Datenbank veröffentlichen, zumal es sich hier offensichtlich um ein Liveprojekt handelt !!!!!!!!!
                  Das ist sicherlich für einige Leute ne Einladung den Server zu übernehmen. Also schleunigst die Daten hier löschen und auf dem Server den Benutzer und das Passwort ändern.

                  Kommentar


                  • #10
                    Zitat von TessaKavanagh Beitrag anzeigen
                    Vielleicht solltest du auch nicht unbedingt die Logindaten für die Datenbank veröffentlichen, zumal es sich hier offensichtlich um ein Liveprojekt handelt !!!!!!!!!
                    Das ist sicherlich für einige Leute ne Einladung den Server zu übernehmen. Also schleunigst die Daten hier löschen und auf dem Server den Benutzer und das Passwort ändern.
                    Keine sorge das ist kein live Projekt, alles lokal aufm eigenen Stand-PC. Und wenn sich einer die mühe machen will sich reinzuhacken, dann soller das machen. Ich muss meine pc in der Woche ca. 3 mal neu aufsetzen da ich ständig einen trojaner bekomme der den pc ausspoiniert, webcam hackt etc.
                    Bin zwar selbst schuld, hab weder firewall noch antivirensystem laufen, allerdings hat dies auch einen Grund.
                    Dementsprechend, wer spaß daran hat dies zu tun und sich reinzuhacken, soll er ma. So richtig was bringen wirds ihm eh nicht.

                    Mit freundlichen Grüßen

                    Dominic Resch aka CaptTaifun

                    Kommentar


                    • #11
                      Hallöchen,

                      ich möchte gerne den Post von Andreas mit ein paar Worten ergänzen. Es wäre vermutlich das sinnvollste, wenn du dein Formular über eine zentrale Konfiguration abrufst und aufbaust. Sprich, du hast irgendwo ein Array, welches die Spalten, Validierungsregeln usw. definiert. Diese kannst du dann nutzen um a) dein HTML-Formular aufzubauen und b) dein Query zu erzeugen. Dies könnte - Achtung, Pseudo-Code - so aussehen:

                      PHP-Code:
                      /**
                       * ./forms/equipment.php
                       * @var [type]
                       */
                      $equipmentForm = [
                          
                      'case' => 'string',
                          
                      'ram' => [2481632],
                          
                      'gpu' => ['nVidia''AMD', ..],
                          
                      'gpuModel' => 'string'
                      ]; 
                      PHP-Code:
                      /**
                       * ./views/equipment-form.html
                       */
                      foreach($equipmentForm as $key => $def){
                          if(
                      $def === 'string'){
                              
                      printf('<input type="text" name="%s" value="">'$key);
                          } elseif(
                      is_array($def)){
                              
                      printf('<select name="%s">'$key);
                              foreach(
                      $def as $value){
                                  
                      printf('<option value="%s">%s</option>'$value$value);
                              }
                              
                      printf('</select>');
                          }

                      PHP-Code:
                      /**
                       * Query
                       */
                      ..
                      foreach(
                      $equipmentForm as $key => $def){
                          
                      $value = isset($_POST[$key]) ? $_POST[$key] : null;
                          if(
                      $validator->validate($value$def)){
                              
                      $stmt->bindParam(':' $key$value);
                          }
                      }
                      .. 
                      Wie / wo du die Eingaben validierst bleibt dir überlassen. Ich habe das der Einfachheit halber mal beim Zusammenbau des Querys platziert. Sollte in der Praxis aber eine Ebene vorher erledigt werden.

                      Viele Grüße,
                      lotti
                      [SIZE="1"]Atwood's Law: any application that can be written in JavaScript, will eventually be written in JavaScript.[/SIZE]

                      Kommentar


                      • #12
                        Zitat von lottikarotti Beitrag anzeigen
                        Hallöchen,

                        ich möchte gerne den Post von Andreas mit ein paar Worten ergänzen. Es wäre vermutlich das sinnvollste, wenn du dein Formular über eine zentrale Konfiguration abrufst und aufbaust. Sprich, du hast irgendwo ein Array, welches die Spalten, Validierungsregeln usw. definiert. Diese kannst du dann nutzen um a) dein HTML-Formular aufzubauen und b) dein Query zu erzeugen. Dies könnte - Achtung, Pseudo-Code - so aussehen:

                        PHP-Code:
                        /**
                         * ./forms/equipment.php
                         * @var [type]
                         */
                        $equipmentForm = [
                            
                        'case' => 'string',
                            
                        'ram' => [2481632],
                            
                        'gpu' => ['nVidia''AMD', ..],
                            
                        'gpuModel' => 'string'
                        ]; 
                        PHP-Code:
                        /**
                         * ./views/equipment-form.html
                         */
                        foreach($equipmentForm as $key => $def){
                            if(
                        $def === 'string'){
                                
                        printf('<input type="text" name="%s" value="">'$key);
                            } elseif(
                        is_array($def)){
                                
                        printf('<select name="%s">'$key);
                                foreach(
                        $def as $value){
                                    
                        printf('<option value="%s">%s</option>'$value$value);
                                }
                                
                        printf('</select>');
                            }

                        PHP-Code:
                        /**
                         * Query
                         */
                        ..
                        foreach(
                        $equipmentForm as $key => $def){
                            
                        $value = isset($_POST[$key]) ? $_POST[$key] : null;
                            if(
                        $validator->validate($value$def)){
                                
                        $stmt->bindParam(':' $key$value);
                            }
                        }
                        .. 
                        Wie / wo du die Eingaben validierst bleibt dir überlassen. Ich habe das der Einfachheit halber mal beim Zusammenbau des Querys platziert. Sollte in der Praxis aber eine Ebene vorher erledigt werden.

                        Viele Grüße,
                        lotti
                        Vielen Dank dafür Lotti!
                        Erstmals tut es mir leid das ich derzeit nicht so aktiv zurückschreibe, allerdings bin ich schwer beschäftigt mit meiner Abschlussarbeit und dem ganzen Webseiten-Gedöns.

                        Ehrlich gesagt weiß ich noch nicht so wirklich was ich mit dem Code anfangen soll. Was ich allerdings versteh, ist:
                        Du hast ein Array erstellt namens equipmentForm, indem alle Felder, für die "Definitionen" (Gehäuse, Graka, etc pp.), drinnen stehen und diese dann in in Formular gelegt werden. Bei der Funktion wird dann überprüft ob ein Textfeld oder ein Selectfeld eingefügt werden soll (je nachdem ob es string oder nicht string is). Anschließend wird alles, wenn das Formular abgeschickt wurde, in das Array gespeichert, welches ich dann in die Datenbank eintragen kann (Was ja allerdings schon die Funktion selbst quasi macht, zumindest fügt es die Felder ein und ersetzt die Sachen mit bindParam).

                        Habe ich dies so richtig verstanden? Wie ich bereits, im ersten Post, erwähnt hatte, habe ich mich noch nie mit Arrays auseinandergesetzt, da ich diese nie nötig hatte. Jetzt allerdings scheint es etwas sinnvoller zu sein.

                        Wenn meine "Erklärung" richtig ist, werde ich mich mal ran setzen und dies austesten. Kann allerdings etwas dauern, da ich alle Websiten gelöscht habe und nun neu anfangen werde (Ich hatte einfach keine Struktur, das soll sich jetzt ändern).

                        Dennoch nochmals herzlichen Dank, auch an dich Andreas!

                        Mit freundlichen Grüßen

                        Dominic Resch aka CaptTaifun

                        Kommentar

                        Lädt...
                        X