“错误”;未定义索引“;使用PHP中的表单

“错误”;未定义索引“;使用PHP中的表单,php,mysql,Php,Mysql,我有这个代码,我有两个问题 一个是这一行: 注意:第65行C:\xampp\htdocs\art-legend\12\edit\index.php中未定义的索引:elm1 “我的本地语言”中的第65行在本页该行 ($editor=$_POST['elm1'];) 还有另一个错误:当我提交代码时,转到no页面(找不到对象!),这是同一页面中的表单代码: <form method="post" action="<? echo $PHP_SELF; ?>">

我有这个代码,我有两个问题 一个是这一行:

注意:第65行C:\xampp\htdocs\art-legend\12\edit\index.php中未定义的索引:elm1

“我的本地语言”中的第65行在本页该行 ($editor=$_POST['elm1'];)

还有另一个错误:当我提交代码时,转到no页面(找不到对象!),这是同一页面中的表单代码:

<form method="post" action="<? echo $PHP_SELF; ?>">

                <div>
                <textarea id="elm1" name="elm1" rows="15" cols="80" style="width: 80%">
            ....
                </textarea>
            </div>
            <br />
        <input type="submit" value="gooooo" name="submit" />

    </form>
<?

$localhost = "localhost";
$user = "root";
$password ="adminpass"; 
$db = "im";

$connect = mysqli_connect($localhost,$user,$password,$db);
$editor = $_POST['elm1'];

$sql = "insert into images(name) values('$editor')";
$query = mysqli_query($connect,$sql);

$sql2 = "select images.name from images";
$query2 = mysqli_query($connect,$sql2);

while ($row = mysqli_fetch_array($query2,MYSQLI_ASSOC)){
    echo $row['name'];

    }

?>
试试这个:

<?php

$localhost = "localhost";
$user = "root";
$password ="adminpass"; 
$db = "im";


$connect = mysqli_connect($localhost,$user,$password,$db);

if(isset($_POST['elm1'])){ //This line
$editor = $_POST['elm1'];
$sql = "insert into images(name) values('".mysqli_real_escape_string($connect, $editor)."')";
$query = mysqli_query($connect,$sql);
}

$sql2 = "select images.name from images";
$query2 = mysqli_query($connect,$sql2);

while ($row = mysqli_fetch_array($query2,MYSQLI_ASSOC)){
echo $row['name'];

}



?>

首次加载页面时,将没有post变量。尝试将您的代码包装到:

 if ($_SERVER['REQUEST_METHOD'] == 'POST') {

 }

也读关于< /p>,请为上帝的爱清理你的输入,或者更好地使用准备好的语句。MyQuiLi RealEnguleScript()增加了答案。至少这是XDOP应该真正考虑的。也许他正在从旧的MySqL**扩展……是的,一个问题现在正在工作,但为什么当我提交去对象找不到!查看html并确保

action=”“
是您所期望的。查看呈现页面的html,确保加载页面时所有内容都正确无误。
 if ($_SERVER['REQUEST_METHOD'] == 'POST') {

 }