Ankündigung

Einklappen
Keine Ankündigung bisher.

[Erledigt] [Problem]MySQL Zeilen werden ausgelesen aber nicht ausgegeben

Einklappen

Neue Werbung 2019

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

  • [Erledigt] [Problem]MySQL Zeilen werden ausgelesen aber nicht ausgegeben

    Hallo allerseits,

    nach mehrmaligen googlen,probieren o.ä. habe ich immer noch keine Lösung gefunden zu meinem Problem:

    Ausschnitt aus der usercp.php:
    PHP-Code:
    <?php
    include 'login.php';
    // Host Connect
    mysql_connect($hostname$username$password) or DIE('Connection to host is failed, perhaps the service is down!');
    // Datenbank Auswahl
    mysql_select_db($dbname) or DIE('Database name is not available!');

    ?>

    <?php

    if(!isset($_SESSION['user_id'])) {
        include (
    'login.php'); 

    } else { 
    /*
        $rank = "SELECT * user_data WHERE author='".$_SESSION['user_id']."'";
            $query = mysql_query($rank) or die(mysql_error());
        echo "<center><table border=\"0\" width=\"458\">";
        $i = 0;

                while($array = mysql_fetch_array($query)) {
                    $i = $i + 1;


                    /*
                    echo "<tr>";
                    echo "<th width=\"50\ ">".$i.\"</th>";
                    echo "<th width=\"270\">".$array["id"]."</th>";
                    echo "<th width=\"155\">".$array["pw"]."</th>";
                    echo "<th width=\"200\">".$array["comment"]."</th>";
                    echo "<th width=\"110\">".$array["date"]."</th>";
                    echo "</tr>";
                    echo "
                    <tr>
                    <th width=\"50\ ">".$i.\"
                    <th width=\"270\">".$array["id"]."
                    <th width=\"155\">".$array["pw"]."
                    <th width=\"200\">".$array["comment"]."
                    <th width=\"110\">".$array["date"]."
                    </tr>";
                    }
    */
    $sql"SELECT * FROM user_data WHERE author='".$_SESSION['user_id']."'";
    $result query($sql) or die(mysql_error());    
    echo 
    "<center><table border=\"0\" width=\"458\">";
    $i 0;
    if (!
    $result) {
        die (
    'Etwas stimmte mit dem Query nicht: '.$db->error);
    }
    echo 
    'Die Ergebnistabelle besitzt '.$result->num_rows." Datensätze<br />\n";
    while (
    $row $result->fetch_both()) { 
        
    $i $i 1;

                    echo 
    "<tr>";
                    echo 
    "<th width=\"50\ ">".$i.\"</th>";
                    echo 
    "<th width=\"270\">".$array["id"]."</th>";
                    echo 
    "<th width=\"155\">".$array["pw"]."</th>";
                    echo 
    "<th width=\"200\">".$array["comment"]."</th>";
                    echo 
    "<th width=\"110\">".$array["date"]."</th>";
                    echo 
    "</tr>";
                    
    /*echo "    
                echo "    
                    <tr>
                    <th width=\"50\ ">".$i.\"
                    <th width=\"270\">".$row["id"]."
                    <th width=\"155\">".$row["pw"]."
                    <th width=\"200\">".$row["comment"]."
                    <th width=\"110\">".$row["date"]."
                    </tr>"; */
                                            
    }    
        echo 
    "</table></center><br>"// close table
    }
    ?>
    Ausschnitt aus der login.php:
    PHP-Code:
    <?php 
    include 'mysql_inc.php';

    // Host Connect
    mysql_connect($hostname$username$password) or DIE('Connection to host is failed, perhaps the service is down!');
    // Datenbank Auswahl
    mysql_select_db($dbname) or DIE('Database name is not available!');

    if(isset(
    $_POST['submit']) && $_POST['submit'] == 'Einloggen') {
        
    $account  mysql_real_escape_string($_POST['username']);
    $code        mysql_real_escape_string($_POST['IDCard']);
    $password mysql_real_escape_string($_POST['Password']);
    $select   "SELECT * FROM $tbl_name WHERE username = '".$account."' AND IDCard = '".$code."' AND Password = PASSWORD('$password')"
    $query    mysql_query($select) or die(mysql_error());
    $result   mysql_num_rows($query);

    if(
    $result 0) {
        
    $fetch mysql_fetch_object($query);
        
    $_SESSION['user_id'] = $fetch->username;  
        echo 
    'Sie haben sich erfolgreich eingeloggt. Sie werden in 5 Sekunden weitergeleitet. <meta http-equiv="refresh" content="5; URL=system/usercp2.php"> ';        
        } else {
        echo 
    '<center>Login fehlgeschlagen!<br>
        <a href="index.php?sys=getpw">Passwort vergessen ?</a><br>
        </center>'
    ;
        }
    }
    ?>

  • #2
    du hast einmal
    PHP-Code:
    $row 
    und das andere mal
    PHP-Code:
    $array 

    Kommentar


    • #3
      Zitat von maxorxy Beitrag anzeigen
      du hast einmal
      und das andere mal
      Danke das war ein Leichtsinnsfehler, jedoch brachte das nicht die Lösung. Wie du unten sehen kannst, hatte ich bereits eine derartige Funktion. Vergeblich

      Kommentar


      • #4
        Hi,

        sind einige Fehler

        $result = query($sql) or die(mysql_error());
        sollte eher

        $result = mysql_query($sql) or die(mysql_error());
        und wie wäre es hier, statt

        while ($row = $result->fetch_both()) {
        lieber

        while ($row = mysql_fetch_array($result)) {
        zu verwenden und natürlich statt

        $array["id"]
        das

        $row["id"]
        wie bereits erwähnt!


        if (!$result) {
        die ('Etwas stimmte mit dem Query nicht: '.$db->error);
        }
        Das hier ist auch ziemlich sinnlos, da du den Code danach weiter ausführst!

        mfg Wolf29

        Kommentar


        • #5
          Zitat von wolf29 Beitrag anzeigen
          Hi,

          sind einige Fehler



          sollte eher



          und wie wäre es hier, statt



          lieber



          zu verwenden und natürlich statt



          das



          wie bereits erwähnt!




          Das hier ist auch ziemlich sinnlos, da du den Code danach weiter ausführst!

          mfg Wolf29
          Danke. Genauso habe ich das ungefähr editiert bereits. War gestern noch zu müde und quake-php liefert auch nur Mist.

          Mein derzeitiger Code(funktioniert immer noch nicht wirklich, es steht nur:
          "Die Ergebnistabelle besitzt 1 Datensätze"

          PHP-Code:
          <?php

          if(!isset($_SESSION['user_id'])) {
              include (
          'login.php'); 

          } else { 
          /*
              $rank = "SELECT * user_data WHERE author='".$_SESSION['user_id']."'";
                  $query = mysql_query($rank) or die(mysql_error());
              echo "<center><table border=\"0\" width=\"458\">";
              $i = 0;

                      while($array = mysql_fetch_array($query)) {
                          $i = $i + 1;


                          /*
                          echo "<tr>";
                          echo "<th width=\"50\ ">".$i.\"</th>";
                          echo "<th width=\"270\">".$array["id"]."</th>";
                          echo "<th width=\"155\">".$array["pw"]."</th>";
                          echo "<th width=\"200\">".$array["comment"]."</th>";
                          echo "<th width=\"110\">".$array["date"]."</th>";
                          echo "</tr>";
                          echo "
                          <tr>
                          <th width=\"50\ ">".$i.\"
                          <th width=\"270\">".$array["id"]."
                          <th width=\"155\">".$array["pw"]."
                          <th width=\"200\">".$array["comment"]."
                          <th width=\"110\">".$array["date"]."
                          </tr>";
                          }
          */
          $sql"SELECT * FROM user_data WHERE author='".$_SESSION['user_id']."'";
          $query mysql_query($sql) or die(mysql_error());
          $result mysql_num_rows($query) or die(mysql_error());        
          echo 
          "<center><table border=\"0\" width=\"458\">";
          $i 0;
          if (!
          $query) {
              die (
          'Etwas stimmte mit dem Query nicht: '.$db->error);
          }
          echo 
          'Die Ergebnistabelle besitzt '.$result." Datensätze<br />\n";
          while (
          $row mysql_fetch_array($query) or die(mysql_error())); { 
              
          $i $i 1;

                          echo 
          "<tr>";
                          echo 
          "<th width=\"50\ ">".$i.\"</th>";
                          echo 
          "<th width=\"270\">".$row["id"]."</th>";
                          echo 
          "<th width=\"155\">".$row["pw"]."</th>";
                          echo 
          "<th width=\"200\">".$row["comment"]."</th>";
                          echo 
          "<th width=\"110\">".$row["date"]."</th>";
                          echo 
          "</tr>";
                          
          /*echo "    
                      echo "    
                          <tr>
                          <th width=\"50\ ">".$i.\"
                          <th width=\"270\">".$row["id"]."
                          <th width=\"155\">".$row["pw"]."
                          <th width=\"200\">".$row["comment"]."
                          <th width=\"110\">".$row["date"]."
                          </tr>"; */
                                                  
          }    
              echo 
          "</table></center><br>"// close table
          }
          ?>

          Kommentar


          • #6
            Hi,

            bei der Zeile

            while ($row = mysql_fetch_array($query) or die(mysql_error()));
            muss das

            while ($row = mysql_fetch_array($query))
            weg...also irgendwie so

            PHP-Code:
            //...
            while ($row mysql_fetch_array($query))

                            
            $i++;
                            echo 
            "<tr>";
                            echo 
            "<th width=\"50\ ">".$i.\"</th>";
                            echo 
            "<th width=\"270\">".$row["id"]."</th>";
                            echo 
            "<th width=\"155\">".$row["pw"]."</th>";
                            echo 
            "<th width=\"200\">".$row["comment"]."</th>";
                            echo 
            "<th width=\"110\">".$row["date"]."</th>";
                            echo 
            "</tr>";
            //...

            mfg Wolf29

            Kommentar


            • #7
              Danke hat geklappt!

              Kommentar

              Lädt...
              X