注意:未定义索引:在第10行注册G:\ xampp \ htdocs \ tg \ 1stSubmit.php

时间:2014-03-27 06:36:48

标签: php mysql

当我在mysql中插入数据时,会生成此错误。

  

注意:未定义的索引:在第10行注册G:\ xampp \ htdocs \ tg \ 1stSubmit.php

enroll<input type="text" name="enroll">中定义,在提交页面上声明:

$a =  $POST['enroll'];
$sql="INSERT INTO student (e_no,f_name) VALUES ('$a','$b')";

2 个答案:

答案 0 :(得分:1)

我猜这是一个错字,

$a =  $_POST['enroll']; //you missed "_" should be _POST

并始终检查post变量是否真的存在,

$a =  isset($_POST['enroll']) ? $_POST['enroll'] : ""; 

Reference

警告: Please, don't use mysql_* functions in new code。它们不再被维护and are officially deprecated。请参阅red box?转而了解prepared statements,并使用PDOMySQLi - this article将帮助您确定哪个。如果您选择PDO here is a good tutorial

答案 1 :(得分:1)

使用

$a = $_POST['enroll'];

而不是

$a = $POST['enroll'];