我正在尝试从我的表单中插入数据,但我不断收到“通知:未定义的索引:第6行的C:\ xampp \ htdocs \ project \ insert.php中的名称”错误。知道怎么解决吗?
代码:
<?php
require_once("db.php");
if(isset($_POST["submit"]))
$name = $_POST["name"];
$course = $_POST["course"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$date = $_POST["date"];
$sql = "INSERT INTO registertb(name, course, email, phone, date) VALUES ('" . $name . "','" . $course . "','" . $email . "','" . $phone . "','" . $date . "')";
$result = mysql_query($sql,$dbconn);
if($result)
{
?>
<script type="text/javascript">
alert('Registration success! ');
//window.location.href='view.php';
</script>
<?php
}
else
{
?>
<script type="text/javascript">
alert('An error occured while inserting your data');
</script>
<?php
}
?>
答案 0 :(得分:0)
您的$_POST
数组没有名称密钥,可能您的使用不使用post但使用get方法。
尝试删除此行:$name = $_POST["name"];
如果您有错误:
注意:未定义的索引:
course
in 第6行的C:\ xampp \ htdocs \ project \ insert.php
所以你可以查看