MySQL – die besten Beiträge

Verschachtelte sql abfrage bzw. sortierung?

So, ich habe ein Problem.

Gerne möchte ich daten als liste aus einer datenbank laden. diese daten sollen seiten anzeigen als tabelle, diese seiten haben aber teilweise untergeordnete seiten die in der datenbank unter 'parent' die 'id' des elternelementes und diese wiederum können auch untergeordnete seiten haben.

wie gestalte ich die datenbankabfrage wenn ich die seiten anzeigen will in einer tabelle in der erst die "Höchste" nach dem 'sort' wert absteigend und zwischen diesem sort und dem nächsten "höchsten" datensatz dazwischen die unterseiten erscheinen?

hier ein bild der Tabelle:

anhin ein codeschnipsel der tabelle die ich schon habe:

<?php if (!empty($pages)): ?>
    <table>
        <thead>
            <tr>
                <th>ID</th>
                <th>Link</th>
                <th>Titel</th>
                <th>Navigationselement</th>
                <th>Aktionen</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach($pages AS $page): ?>
                <tr>
                    <td><?php echo e($page->id); ?></td>
                    <td><?php echo e($page->slug); ?></td>
                    <td><?php echo e($page->title); ?></td>
                    <td><?php echo e($page->nav); ?></td> 
                    <td>
                        <form method="POST" action="./?route=admin/page/delete">
                            <input type="hidden" name="csrf_token" value="<?php echo csrf_token(); ?>" />
                            <input type="hidden" name="id" value="<?php echo e($page->id); ?>" />
                            <input type="submit" value="Löschen" class="button-as-link" />
                        </form>
                        <a href="./?route=admin/page/edit&id=<?php echo e($page->id); ?>">Editieren</a>
                    </td>
                </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
<?php else: ?>
    <p>Es wurden noch keine Seiten angelegt.</p>
<?php endif; ?>
Bild zum Beitrag
SQL, Datenbank, MySQL, PHP

Nodejs mariadb Column count doesn't match value count at row 1?

meine datenbank hat 4 spalten aber ich setze nur 3 ein weil die letzte eine auto_increment spalte ist,

ich nutze nodejs mit mariadb und habe folgende fehlermeldung beim daten einsetzen:

/home/j44/Downloads/themer/tut/node_modules/mariadb/lib/misc/errors.js:64
  return new SqlError(msg, sql, fatal, info, sqlState, errno, additionalStack, addHeader);
         ^

SqlError: (conn=2420, no: 1136, SQLState: 21S01) Column count doesn't match value count at row 1
sql: INSERT INTO thread value (no, head, ts) - parameters:['1171187570193989762','rrrrrrrrrrrrrrrr',1699303276347]
    at module.exports.createError (/home/j44/Downloads/themer/tut/node_modules/mariadb/lib/misc/errors.js:64:10)
    at PacketNodeEncoded.readError (/home/j44/Downloads/themer/tut/node_modules/mariadb/lib/io/packet.js:582:19)
    at Query.readResponsePacket (/home/j44/Downloads/themer/tut/node_modules/mariadb/lib/cmd/parser.js:58:28)
    at PacketInputStream.receivePacketBasic (/home/j44/Downloads/themer/tut/node_modules/mariadb/lib/io/packet-input-stream.js:85:9)
    at PacketInputStream.onData (/home/j44/Downloads/themer/tut/node_modules/mariadb/lib/io/packet-input-stream.js:135:20)
    at Socket.emit (node:events:514:28)
    at addChunk (node:internal/streams/readable:376:12)
    at readableAddChunk (node:internal/streams/readable:349:9)
    at Readable.push (node:internal/streams/readable:286:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  sqlMessage: "Column count doesn't match value count at row 1",
  sql: "INSERT INTO thread value (no, head, ts) - parameters:['1171187570193989762','rrrrrrrrrrrrrrrr',1699303276347]",
  fatal: false,
  errno: 1136,
  sqlState: '21S01',
  code: 'ER_WRONG_VALUE_COUNT_ON_ROW'
}


SQL, programmieren, JavaScript, Datenbank, MySQL, node.js, Discord, Discord Bot

Unity Loginsystem mit PHP 500 Error?

Hallo, wisst ihr vielleicht warum dieser Code nicht funktioniert?

Ich habe einen Root Server mit MariaDB, PHP 8.2 und phpMyAdmin.

Das ist mein Servercode:

<?php

  $servername = "localhost";
  $username = "blabla";
  $password = "blabla";
  $dbname = "blabla";

  // variables submited by user
  $loginUser = $_POST["loginUser"];
  $loginPass = $_POST["loginPass"];

  // Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);

  // Check connection
  if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
  }

  echo "Conected successfully, now we will show the users.<br><br>";

  $sql = "SELECT password FROM users WHERE username = " . $loginUser;
  $result = $conn->query($sql);

  if ($result->num_rows > 0) {
    // output data of each row
    while ($row = $result->fetch_assoc()) {
      if ($row["password"] == $loginPass) {
        echo "login Success";
      }
      else {
        echo "wrong credentials";
      }
    }
  }
  else {
    echo "Username does not exist";
  }

  $conn->close();
?>

Das ist mein Unity-Code:

void Start()
{
  // A correct website page.
  StartCoroutine(Login("testuser", "123456"));
}

IEnumerator Login(string username, string password)
{
  WWWForm form = new WWWForm();
  form.AddField("loginUser", username);
  form.AddField("loginPass", password);

  using (UnityWebRequest www = UnityWebRequest.Post("http://blabla/Login.php", form))
  {
    yield return www.SendWebRequest();

    if www.result != UnityWebRequest.Result.Success)
    {
      Debug.Logwww.error);
    }
    else
    {
      Debug.Logwww.downloadHandler.text);
    }
  }
}

In Unity bekomme ich folgende Fehlermeldung:

Und wenn ich auf das PHP-Dokument im Internet gehe:

Danke für eure Hilfe.

Bild zum Beitrag
Webseite, Code, MySQL, PHP, Unity

Flutter Data from API?

Hey, will Daten von meiner erstellten API ausgeben in meiner App.

Code:

fetchData() async {
    final response = await http.get(Uri.parse('http://localhost/list.json'));
    return json.decode(response.body);
  }

FutureBuilder(
            future: fetchData(),
            builder: (BuildContext context, AsyncSnapshot snapshot){
              if(snapshot.hasError){
                return Center(
                  child:Text("Error"),
                );
              }
              if(snapshot.hasData){
                return ListView.builder(
                  itemCount: snapshot.data.length, 
                    itemBuilder: (BuildContext context, int index){
                  return Row(
                    children: [
                      Expanded(
                        child: Container(
                        child: Column(
                          children: [
                            Text(snapshot.data[index]['id']),
                            SizedBox(height: 10,),
                            Text(snapshot.data[index]['name']),
                            
                          ],
                        ),
                        ),
                      ),
                    ],
                  );
                });
              }
              return Center(child: CircularProgressIndicator(),);
            },
          ),

Jedoch bekomm ich als Ausgabe "Error". Woran kann das liegen? Die API kann ich mit Postmann abfragen.

App, Technik, programmieren, iOS, Android, Dart, Entwicklung, MySQL, Programmiersprache, Rest, Softwareentwicklung, API, localhost, app entwicklung, Flutter

Warum kann dieser php code keine Verbindung zur Datenbank herstellen?

Ich sitze hier und verzweifle förmlich daran, warum sich die eingegebenen Daten aus:

<!DOCTYPE html>
<html>
  <head>
    <h1>Der Weg ins Paradies</h1>
    <link rel="stylesheet" href="GL.css">
  </head>
    <p>Die Welt dadraußen ist trist, doch <br> sein kein Schaf, sei ein Wolf</p>
    <form method="post" action="Registrierungsseite.php">
      <p><label>Name:<br><input type="text" name="Name"></label></p>
      <p><label>E-Mail:<br><input type="text" name="Mail"></label></p>
      <p><label>Passwort:<br><input type="password" name="Passwort"></label></p>
      <p><label>IBAN:<br><input type="text" name="IBAN"></label></p>
      <p><input type="submit" value="Registrieren"></p>
    </form>
  </body>
</html>

nicht in der MySQL-Datenbank wiederfinden.

Meine PHP-Datei ist diese hier:

<?php
  // Get the form data
  $name = $_POST['name'];
  $email = $_POST['email'];
  $password = $_POST['password'];
  $iban = $_POST['iban'];

  // Connect to the MySQL database
  $db = mysqli_connect("localhost", "root", "", "paradies");

  // Check if the connection was successful
  if (mysqli_connect_errno()) {
    // If the connection failed, display an error message and exit
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    exit;
  }

  // Insert the form data into the MySQL database
  $query = "INSERT INTO paradies (name, email, password,iban) VALUES ('$name', '$email', '$password', '$iban')";

  if (mysqli_query($db, $query)) {
    // If the insert was successful, redirect the user to the login page
    header("Location: GL.php");
    exit;
  }
  else {
    // If the insert failed, display an error message
    echo "Error: " . $query . "<br>" . mysqli_error($db);
  }

  // Close the MySQL connection
  mysqli_close($db);
?>

Ich sehe den Fehler einfach nicht, da sobald man die Daten absendet, es zwar zur PHP-Datei weitergeleitet wird, dann jedoch lediglich der Code zu sehen ist. Die Datenbank hat dann natürlich auch keinen Eintrag.

Danke im Voraus.

HTML, Datenbank, MySQL, PHP, phpMyAdmin

Was heißt diese C# Fehlermeldung und wie löst man das Problem?

Hallo,

Ich bekomme immer diese Fehlermeldung beim ausführen:

System.ArgumentException: "Format of the initialization string does not conform to specification starting at index 0."

Das ist mein Code:

using System;
using MySql.Data.MySqlClient;
namespace Database_projekt
{
  class Program
  {
    static void Main(string[] args)
    {
      string verbindungsdaten = "SERVER=localhost;" + "DATABASE=dtbs;" + "UID=admin;" + "PASSWORD=Wasd200!;";
      MySqlConnection verbindung = new MySqlConnection("verbindungsdaten");

      Console.WriteLine("Bitte geben sie die Artikelnummer ein.");
      int artikelnummer = int.Parse(Console.ReadLine());

      Console.WriteLine("Bitte geben sie den Fahrradtyp ein.");
      string typ = Console.ReadLine();

      Console.WriteLine("Bitte geben sie die Farbe ein.");
      string farbe = Console.ReadLine();

      Console.WriteLine("Bitte geben sie den Preis ein.");
      Console.WriteLine("Euro: ");
      double preisEuro = double.Parse(Console.ReadLine());
      Console.WriteLine("Cent: ");
      double preisCent = double.Parse(Console.ReadLine());



      string befehl = "INSERT INTO fahrraeder VALUES(" +
        artikelnummer + ",' " +
        typ + " ' ,'" +
        farbe + "' ," +
        preisEuro + "." + preisCent + ");";

      MySqlCommand befehlsobjekt = new MySqlCommand(befehl);
      befehlsobjekt.Connection = verbindung;

      verbindung.Open();
      befehlsobjekt.ExecuteNonQuery();
      verbindung.Close();

      string befehl2 = "SELECT * FROM fahrraeder;";

      MySqlCommand befehlsobjekt2 = new MySqlCommand(befehl2);
      befehlsobjekt.Connection = verbindung;

      MySqlDataReader Reader;
      verbindung.Open();

      Reader = befehlsobjekt2.ExecuteReader();
      while (Reader.Read())
      {
        string zeile = "";
        for (int i = 0; i < Reader.FieldCount; i++) 
        zeile += Reader.GetValue(i).ToString() + " ";
        Console.WriteLine(zeile);
      }


      verbindung.Close();


    }
  }
}

Wie löst man das?

C Sharp, Datenbank, MySQL, Visual Studio

Meistgelesene Beiträge zum Thema MySQL