PHP – die besten Beiträge

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

c# http post request?

C#

            var httpClient = new HttpClient();
            var values = new Dictionary<string, string>
            {
                { "username", UsernameTextBox.Text },
                { "email", EmailTextBox.Text }
            };

            var content = new FormUrlEncodedContent(values);

            var response = await httpClient.PostAsync("http://subdomain.domain.tld/file.php", content);

            var responseString = await response.Content.ReadAsStringAsync();
            FSCMessageBox.Show(responseString);

PHP

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHP/PHPMailer/src/Exception.php';
require 'PHP/PHPMailer/src/PHPMailer.php';
require 'PHP/PHPMailer/src/SMTP.php';
$mail = new PHPMailer(true);
$whitelist = array("...");
$auth = false;
foreach($whitelist as $ip)
{
    if($ip == $_SERVER['REMOTE_ADDR']) {$auth = true;}
}
if(!$auth)
{
    http_response_code(403);
    exit();
}
try
{
    $code = "";
    for ($i = 0; $i < 8; $i++)
    {
        $ascii = rand(48, 122);
        if ($ascii > 57 && $ascii < 65 || $ascii > 90 && $ascii < 97)
        {
            $ascii -= 7;
        }
        $code .= chr($ascii);
    }
    echo $code;
    $mail->SMTPDebug = 2;                                       
    $mail->isSMTP();                                            
    $mail->Host       = "...";                    
    $mail->SMTPAuth   = true;                             
    $mail->Username   = "...";                 
    $mail->Password   = "...";                        
    $mail->SMTPSecure = "tls";                              
    $mail->Port       = 587;  
    $mail->setFrom("...", "...");           
    $mail->addAddress($_POST['email']);          
    $mail->isHtml();       
    $mail->Subject = "Verification Code";
    $mail->Body    = 
    "
    <h1>Hello, ".$_POST['username']."!</b1>
    <h4>Your verification code is ".$code.".</h4>
    <p>If you don't know why you received this E-Mail, you can safely ignore and delete it.</p>
    ";
    $mail->send();
    http_response_code(200);
}
catch (Exception $e)
{
    http_response_code(503);
    exit(); 
}
?>

Ist da ein Fehler? Wenn ich den php code ohne dem Post Request und mit festen Werten ausführe, geht alles. Also muss es doch am c# code liegen, oder?

Wenn ich es mit dem Post Request versuche, wird im Programm eine MessageBox angezeigt, wo einfach garnichts drin steht.

FSCMessageBox.Show(responseString);

Email wird auch nicht verschickt.

Die Daten wie host, username, password, email etc. sind alle richtig, da liegt der Fehler nicht.

HTML, Webseite, PHP, Webentwicklung

Meistgelesene Beiträge zum Thema PHP