简体   繁体   English

未定义索引-创建文章

[英]Undefined index - Create Article

UNDEFINED INDEX AT LINE 20 第20行的未定义指标

Problem is at $tekst and $titel, somehow it is not defined correct. 问题出在$ tekst和$ titel,以某种方式未正确定义。 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. 这有点像我,因为它在我的register.php中工作正常,并且以相同的方式编写。

<?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>";

        }

    ?>

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. 它可能已在另一个文件中起作用,因为您仅在表单发布期间渲染了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM