• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

PHP Mailversand (Problem)

Marvin231

Neues Mitglied
Hi, ich hab script erstellt, dass ein Formular an eine E-Mail Adresse senden soll. Die Daten nimmt er aus einer Datenbank, die so aussieht: [TABLE="class: grid, width: 500"]
[TR]
[TD]ID
[/TD]
[TD]username
[/TD]
[TD]vorname
[/TD]
[TD]nachname
[/TD]
[TD]jahrgang
[/TD]
[TD]Passwort
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[/TABLE]

Das Formular sieht so aus:
PHP:
<?php
session_start();
if(isset($_SESSION["username"])) {
?>
<!doctype html>
<html>
<head>
<title>LGR App - Meldeliste</title>
<style type="text/css">
            
<!--
#jahrgang {
                
                margin-left: auto;
                margin-right: auto;
                width: 400px;
                height: 200px;
                background-color: #f02a2a;
                text-align: center;
                border-radius: 5px;
            }
            
#disziplinen {
text-align: center;
}

#senden {
text-align: right;
}
-->
</style>
    </head>
    <body>
        <div id="jahrgang">
        
            <form method="POST">
                
                <b></br>Wettkampf:</b>
                <select name="wettkampf" size="1">
                    <option>Wettkampf ausw&auml;hlen</option>
                    <option value="wettkampf1">Wettkampf 1</option>
                   
                
                </select>
                <b></br></br></br>Jahrgang:</b>
                <select name="jahrgang" size="1">
                    <option>Jahrgang ausw&auml;hlen</option>
                    <option>2005</option>
                    <option>2004</option>
                    <option>2003</option>
                    <option>2002</option>
                    <option>2001</option>
                    <option>2000</option>
                    <option>1999</option>
                    <option>1998</option>
                    <option value="1997">1997</option>
                    <option>1996</option>
                    <option>1995</option>
                    <option>1994</option>
                    <option>1993</option>
                    <option>1992</option>
                    <option>1991</option>
                    <option>1990</option>
                    <option>1989</option>
                    <option>1988</option>
                    <option>1987</option>
                    <option>1986</option>
                    <option>1985</option>
                    <option>1984</option>
                    <option>1983</option>
                    <option>1982</option>
                    <option>1981</option>
                    <option>1980</option>
                </select>
                </br></br></br>
                <input type="submit" value="Weiter" />
                </br></br></br></br></br>
                </form>
                </div>
                <div id="disziplinen">
                    <form action="mail.php" method="POST">
                <?php
         if (($_POST['jahrgang'] == 1980) AND ($_POST['wettkampf'] == "wettkampf1"))  {
         ?>
    
<h2>1980</h2>

<table width="60%" align="center">
    <tr>
        <td width="20%"><input type="checkbox" name="disziplin[]" value="100m"> 100m</td>
        <td width="20%"><input type="checkbox" name="disziplin[]" value="200m"> 200m</td>
        <td width="20%"><input type="checkbox" name="disziplin[]" value="300m"> 300m</td>
    </tr>
    <tr>
        <th colspan="3"><br/><input type="submit" value="Senden"></th>
    </tr>
</table>

    <?php
} else {
    //Zugrif verweigert
}  
?>

<?php
         if (($_POST['jahrgang'] == 1981) AND ($_POST['wettkampf'] == "wettkampf1"))  {
         ?>
    
<h2>1981</h2>

<table width="60%" align="center">
<tr>
        <td width="20%"><input type="checkbox" name="100m" value="100m"> 100m</td>
        <td width="20%"><input type="checkbox" name="100m" value="100m"> 100m</td>
        <td width="20%"><input type="checkbox" name="100m" value="100m"> 100m</td>
    </tr>
    <tr>
        <th colspan="3"><br/><input type="submit" value="Senden"></th>
    </tr>
</table>

    <?php
} else {
    //Zugrif verweigert
}  
?>

<?php
         if (($_POST['jahrgang'] == 1982) AND ($_POST['wettkampf'] == "wettkampf1"))  {
         ?>
    
<h2>1982</h2>

<table width="60%" align="center">
<tr>
        <td width="20%"><input type="checkbox" name="100m" value="100m"> 100m</td>
        <td width="20%"><input type="checkbox" name="100m" value="100m"> 100m</td>
        <td width="20%"><input type="checkbox" name="100m" value="100m"> 100m</td>
    </tr>
    <tr>
        <th colspan="3"><br/><input type="submit" value="Senden"></th>
    </tr>
</table>

    <?php
} else {
    //Zugrif verweigert
}  
?>

<?php
         if (($_POST['jahrgang'] == 1983) AND ($_POST['wettkampf'] == "wettkampf1"))  {
         ?>
    
<h2>1983</h2>

<table width="60%" align="center">
<tr>
        <td width="20%"><input type="checkbox" name="100m" value="100m"> 100m</td>
        <td width="20%"><input type="checkbox" name="100m" value="100m"> 100m</td>
        <td width="20%"><input type="checkbox" name="100m" value="100m"> 100m</td>
    </tr>
    <tr>
        <th colspan="3"><br/><input type="submit" value="Senden"></th>
    </tr>
</table>

    <?php
} else {
    //Zugrif verweigert
}  
?>

<?php
         if (($_POST['jahrgang'] == 1984) AND ($_POST['wettkampf'] == "wettkampf1"))  {
         ?>
    
<h2>1984</h2>

<table width="60%" align="center">
<tr>
        <td width="20%"><input type="checkbox" name="100m" value="100m"> 100m</td>
        <td width="20%"><input type="checkbox" name="100m" value="100m"> 100m</td>
        <td width="20%"><input type="checkbox" name="100m" value="100m"> 100m</td>
    </tr>
    <tr>
        <th colspan="3"><br/><input type="submit" value="Senden"></th>
    </tr>
</table>

    <?php
} else {
    //Zugrif verweigert
}  
?>

<?php
         if (($_POST['jahrgang'] == 1985) AND ($_POST['wettkampf'] == "wettkampf1"))  {
         ?>
    
<h2>1985</h2>

<table width="60%" align="center">
<tr>
        <td width="20%"><input type="checkbox" name="100m" value="100m"> 100m</td>
        <td width="20%"><input type="checkbox" name="100m" value="100m"> 100m</td>
        <td width="20%"><input type="checkbox" name="100m" value="100m"> 100m</td>
    </tr>
    <tr>
        <th colspan="3"><br/><input type="submit" value="Senden"></th>
    </tr>
</table>

    <?php
} else {
    //Zugrif verweigert
}  
?>

<?php
         if (($_POST['jahrgang'] == 1986) AND ($_POST['wettkampf'] == "wettkampf1"))  {
         ?>
    
<h2>1986</h2>

<table width="60%" align="center">
<tr>
        <td width="20%"><input type="checkbox" name="100m" value="100m"> 100m</td>
        <td width="20%"><input type="checkbox" name="100m" value="100m"> 100m</td>
        <td width="20%"><input type="checkbox" name="100m" value="100m"> 100m</td>
    </tr>
    <tr>
        <th colspan="3"><br/><input type="submit" value="Senden"></th>
    </tr>
</table>

    <?php
} else {
    //Zugrif verweigert
}  
?>


   </form>
                    </div>     


            
     
    </body>
</html>

<?php
} else {
   ?>
Bitte erst einloggen, <a href="index.php">hier</a>.
<?php
}
?>

Der PHP-Code sieht so aus:

PHP:
<?php
session_start();
if(isset($_SESSION["username"])) {

$con = mysqli_connect("localhost", "***", "***")
        or die ("Fehler im System");

mysqli_select_db($con, "***")
        or die ("Verbindung zur Datenbank war nicht möglich...");

$res = mysqli_query($con, "select * from login");

$num = mysqli_num_rows($res);

while ($dsatz = mysqli_fetch_assoc($res))
{

$from = "Meldeliste";
$to = "***@hotmail.com";
$betreff = "Meldung";

$vorname = $dsatz["vorname"];
$nachname = $dsatz["nachname"];
$jahrgang = $dsatz["jahrgang"];
$disziplin = "";
if (isset($_POST["disziplin"]))
   $disziplin = implode(", ", $_POST["disziplin"]);

$message = "Vorname: ". $vorname."\n" . "Nachname: ". $nachname."\n" . "Jahrgang: ". $jahrgang."\n"."\n". "Disziplinen: ". "\n"."\n". $disziplin;

mail($to, $betreff, $message, $from);

}
mysqli_close($con);
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        Meldung wurde erfolgreich versendet!
    </body>
</html>

<?php
} else {
   ?>
Bitte erst einloggen, <a href="index.php">hier</a>.
<?php
}
?>

Wenn ich jetzt auf den submit Button drück erhalt ich 3 Mails, also von jeder Person aus der Datenbank. Ich will aber nur von der Person, die auf der Website ist, die Daten haben. Kann mir jemand sagen, was ich Falsch gemacht hab?

Viele Grüße
Marvin231
 
Zuletzt bearbeitet:
Das habe ich dir schon mal geschrieben, hänge hier
PHP:
$res = mysqli_query($con, "select * from login");
eine Bedingung mit dem Usernamen an
 
Geht es so?:

PHP:
$username = $dsatz["username"];
$res = mysqli_query($con, "select * from Login where $username");
 
Zurück
Oben