这个未定义的索引消息是什么意思


What does this undefined index message mean

每次加载页面时,这段代码都会调用输入到表单中的值,并将它们输入到数据库中(或者至少应该如此),它会给出"未定义索引"消息,我很难确定原因。

我们非常感谢能为我提供的任何帮助!

<?php
$dbc=mysql_connect('localhost', 'user', '');
mysql_select_db('database', $dbc);

$sqlInsertString = "INSERT INTO band_information (Name, Photo, Bio, City, State, Zipcode, Genre, Link)
            VALUES ({$_POST['bandname']}, {$_FILES['bandphoto']['name']}, {$_POST['bandbio']}, {$_POST['bandcity']},
                    {$_POST['bandstate']}, {$_POST['bandzipcode']}, {$_POST['bandgenre']},{$_POST['bandlink']});";
if($_SERVER['REQUEST_METHOD']=='POST'){
    if(move_uploaded_file($_FILES['bandphoto']['tmp_name'], "C:''HTML''mgertenbach''BAND''photos''{$_FILES['bandphoto']['name']}") && $mysql_query($sqlinsertString, $dbc)){
        print '<p>Thanks for submitting your band!</p>';
    } else {
        print '<p>Could not submit band because: <br/>' .
        mysql_error($dbc) . '</p>';
    }
}   

由于要从<form>中获取值,因此需要首先检查这些值是否已设置。

为此,您应该使用isset构造。像这个

if(!isset($_POST['bandname'])) // And whichever variables you get from your <form>
{
echo "Band Name was not Provided";
exit;
}
else
{
//.... do your CRUD operations here
}

其次,您正在使用mysql_*函数,这些函数很快就会被弃用。请切换到MySQliPDO