1

I've writing html in a php-file because I want to add php-code. I created a form which was visible. After I add the php code the form wasn't visible on my website. The table that is in the php code is also invisible.

The php code is customized to my MySQL Database.

<!DOCTYPE html>
<html>

<head>
<title>Anmeldung</title>

<meta charset="UTF-8">
<meta name="description" content="">
<meta name="author" content="">
<meta name="keywords" content="">
<meta name="generator" content="Webocton - Scriptly (www.scriptly.de)">

<link href="style.css" type="text/css" rel="stylesheet">
</head>

<body>
<h1 class="Titeltext">Anmeldung</h1>

<?php include('navbar.html'); ?>

<br />
<br />
<br />


<?php
require 'inc/db.php';
if (isset($_POST['aktion']) and $_POST['aktion']=='anmelden') {
    $wettbewerb = "";
    if (isset($_POST['wettbewerb'])) {
        $wettbewerb = trim($_POST['wettbewerb']);
    }
    $nickname = "";
    if (isset($_POST['nickname'])) {
        $nickname = trim($_POST['nickname'])
    }
    $erstellt = date("Y-m-d H:i:s");
    if ( $wettbewerb != '' or $nickname != '' )
    {
        // speichern
        $einfuegen = $db->prepare("
                INSERT INTO anmeldung (wettbewerb, nickname, erstellt) 
                VALUES (?, ?, NOW())
                ");
        $einfuegen->bind_param('sss', $wettbewerb, $nickname);
        if ($einfuegen->execute()) {
            header('Location: anmeldung.php?aktion=anmeldunggespeichert');
            die();
            echo "<h1>angemeldet</h1>";
        }
    }   
}
if (isset($_GET['aktion']) and $_GET['aktion']=='anmeldunggespeichert') {
    echo '<p class="anmeldungerfolg">Deine Anmeldung wurde gespeichert</p>';
}
$daten = array();
if ($erg = $db->query("SELECT * FROM anmeldung")) {
    if ($erg->num_rows) {
        while($datensatz = $erg->fetch_object()) {
            $daten[] = $datensatz;
        }
        $erg->free();
    }   
}
if (!count($daten)) {
    echo "<p>Es liegen keine Daten vor :(</p>";
} else {
?>
<table>
    <thead>
        <tr>
            <th>Wettbewerb</th>
            <th>Nickname</th>
            <th>erstellt</th>
        </tr>
    </thead>
    <tbody>
<?php
        foreach ($daten as $inhalt) {
        ?>
            <tr>
                <td><?php echo $inhalt->wettbewerb; ?></td>
                <td><?php echo bereinigen($inhalt->nickname); ?></td>
                <td><?php echo $inhalt->erstellt; ?></td>
            </tr>
        <?php
        }
        ?>
    </tbody>
</table>
<?php   
}
function bereinigen($inhalt='') {
    $inhalt = trim($inhalt);
    $inhalt = htmlentities($inhalt, ENT_QUOTES, "UTF-8");
    return($inhalt);
}
?>
<form action="" method="post">
    <label>Wettbewerb: 
        <select name="top5" size="5">
            <option>FCS</option>
            <option>Team Liga</option>
            <option>Premiere League</option>
        </select>
    </label>
    <label>Nickname: 
        <input type="text" name="nickname" id="nickname">
    </label>
    <input type="hidden" name="aktion" value="anmelden">
    <input type="submit" value="anmelden">
</form>


</body>
</html>
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • 2
    I would say you need to start by comment out all PHP code. Then you activate a code chunk, bit by bit. By doing so, you can isolate which area that are causing the problem. When you have commented out everything, add an echo within PHP to see that your system can print out the echo. – Toolbox May 06 '20 at 12:32

1 Answers1

0

First of all, you should check whether you're actually displaying errors or not. This is well covered in this topic.

Because if you had enabled error reporting, you would have seen the following:

Parse error: syntax error, unexpected '}' in /websklave/stackoverflow.php on line 36

And why is that? You're lacking a semicolon in line 35:

$nickname = trim($_POST['nickname'])

should be

$nickname = trim($_POST['nickname']);
                                    ^ please, don't forget me. I am always so alone :(
maio290
  • 6,440
  • 1
  • 21
  • 38