Hilfe mit PHP und MySQL

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hilfe mit PHP und MySQL

    Hallo!!
    Ich habe folgendes Skript geschrieben:
    Code:
    <!DOCTYPE HTML>
    <html lang="de">
    <head>
        <meta charset="utf-8">
    	<title>Länderdaten nach Regionen</title>
    <?php
    try {
    	$pdo = new PDO ( 'mysql:dbname=nation;charset=utf8', 'root', '' );
    	//$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    	//$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    } catch ( PDOException $e ) {
    	die ( $e->getMessage () );
    }
    
    
    ?>
    </head>
    
    <body>
    <form method="post">
    <?php
        $sql = "SELECT name, region_id FROM regions ORDER BY name";
        $stmt = $pdo -> prepare($sql);
        $stmt -> execute();
        //print_r($stmt->fetchAll(PDO::FETCH_ASSOC));
        echo "<select name ='auswahl' id = 'auswahl'>";
        
        foreach ($stmt->fetchAll(PDO::FETCH_COLUMN,0) as $daten)
            echo "<option value = $daten>".$daten."</option>";
        echo "</select>";
        if(isset($_POST['auswahl'])){
           $region = $_POST['auswahl'];
            print_r($_POST['auswahl']);
           /* $auswahl = 'SELECT countries.name, countries.area, country_stats.gdp AS "AVG BIP", country_stats.population, continents.name FROM 
                        countries, country_stats, regions INNER JOIN continents ON regions.continent_id = continents.continent_id 
                        WHERE regions.region_id = countries.region_id AND countries.country_id = country_stats.country_id AND regions.region_id = '.$region.' GROUP BY countries.country_id';
            $stmt = $pdo -> prepare($auswahl);
           $ausgabe[] = $stmt -> execute();
           foreach ($ausgabe as $ausgeben)
           echo $ausgeben;*/
        }
    ?>
    <br>
    <input type = "submit" value ="anzeigen">
    </form>	
    	
    
    	</body>
    </html>
    Im zweiten SELECT kann er eine Tabellenspalte (die auswahl des Users) nicht finden. Ich komme aber nicht dahinter wo der fehler liegt.
    Könnt ihr mir bitte helfen?
    Click image for larger version

Name:	Screenshot (2).jpg
Views:	1
Size:	119.2 KB
ID:	1029625
    Im Anhang ist eine Darstellung RDBMS
    Last edited by Ch1co0908; 12-02-2022, 14:14.

  • #2
    Wie lautet denn die genaue Fehlermeldung? Wenn du schon PDO einsetzt, was gut ist, dann solltest du auch prepare() richtig verwenden, und nicht irgendwele Werte ins SQL einbauen.

    Siehe: https://phpdelusions.net/pdo#prepared

    Comment


    • #3
      Originally posted by Ch1co0908 View Post
      Hallo!!
      Ich habe folgendes Skript geschrieben:
      Code:
      <!DOCTYPE HTML>
      <html lang="de">
      <head>
      <meta charset="utf-8">
      <title>Länderdaten nach Regionen</title>
      <?php
      try {
      $pdo = new PDO ( 'mysql:dbname=nation;charset=utf8', 'root', '' );
      //$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      //$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
      } catch ( PDOException $e ) {
      die ( $e->getMessage () );
      }
      
      
      ?>
      </head>
      
      <body>
      <form method="post">
      <?php
      $sql = "SELECT name, region_id FROM regions ORDER BY name";
      $stmt = $pdo -> prepare($sql);
      $stmt -> execute();
      //print_r($stmt->fetchAll(PDO::FETCH_ASSOC));
      echo "<select name ='auswahl' id = 'auswahl'>";
      
      foreach ($stmt->fetchAll(PDO::FETCH_COLUMN,0) as $daten)
      echo "<option value = $daten>".$daten."</option>";
      echo "</select>";
      if(isset($_POST['auswahl'])){
      $region = $_POST['auswahl'];
      print_r($_POST['auswahl']);
      /* $auswahl = 'SELECT countries.name, countries.area, country_stats.gdp AS "AVG BIP", country_stats.population, continents.name FROM
      countries, country_stats, regions INNER JOIN continents ON regions.continent_id = continents.continent_id
      WHERE regions.region_id = countries.region_id AND countries.country_id = country_stats.country_id AND regions.region_id = '.$region.' GROUP BY countries.country_id';
      $stmt = $pdo -> prepare($auswahl);
      $ausgabe[] = $stmt -> execute();
      foreach ($ausgabe as $ausgeben)
      echo $ausgeben;*/
      }
      ?>
      <br>
      <input type = "submit" value ="anzeigen">
      </form>
      
      
      </body>
      </html>
      Im zweiten SELECT kann er eine Tabellenspalte (die auswahl des Users) nicht finden. Ich komme aber nicht dahinter wo der fehler liegt. basketball stars
      Könnt ihr mir bitte helfen? ​
      [ATTACH]3392[/ATTACH]
      Im Anhang ist eine Darstellung RDBMS
      Bitte teilen Sie mir mit, ob das Problem behoben wurde.

      Comment


      • #4
        Originally posted by dmuotif View Post

        Bitte teilen Sie mir mit, ob das Problem behoben wurde.
        Echt jetzt? Der Thread ist vom 12.02.2022

        Comment

        Working...
        X