Question

UNDEFINED INDEX AT LINE 20

Problem is at $tekst and $titel, somehow it is not defined correct. How could be defined otherwise? It's kinda buggin me since it worked fine in my register.php and it is written the same way.

<?php
        session_start();

        if(!isset($_SESSION['amyusername']))
        {
            header("location:admin.php");
        }

        $amyusername = $_SESSION['amyusername'];

        $host = "localhost";
        $username = "root";
        $password = "";
        $db_name = "login";
        $tbl_name = "nyheder";

        mysql_connect("$host", "$username", "$password") or die ("<p class=\"fejl\">Kunne ikke oprette forbindelse til MySQL</p>");
        mysql_select_db("$db_name") or die ("<p class=\"fejl\">Kunne ikke oprette forbindelse til databasen!</p>");

        $titel = mysql_real_escape_string($_POST['titel']);
        $tekst = mysql_real_escape_string($_POST['tekst']);

        if($_POST['titel'] && $_POST['tekst']) {


            $sql = "SELECT * FROM $tbl_name";
            $result = mysql_query($sql);
            $count = mysql_num_rows($result);

            $counter = $count + 1;

            mysql_query("INSERT INTO $tbl_name (Id, Af, Titel, Tekst) VALUES ('$counter', '$amyusername', '$titel', '$tekst')");
            echo "<p class=\"korrekt\">Artiklen er bleven oprettet!</p>";
            header("refresh: 3, indleg.php");


        }
        else {
            echo "<p class=\"fejl\">Du skal udfylde alle felterne!</p>";

        }

    ?>
Was it helpful?

Solution

you should not evaluate the variable but check to see if the index is present.

if(isset($_POST['titel']) && isset($_POST['tekst'])) {

it may have worked in the other file because you rendered it only during a form post.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top