我正在制作一个更新数据库的程序,当我点击更新按钮时,它会显示如下错误:
Notice: Undefined offset: 2 in C:\xampp\htdocs\maritime_database\students_entry.php on line 103
Notice: Undefined offset: 1 in C:\xampp\htdocs\maritime_database\students_entry.php on line 103
它位于第103行的某处,这是代码:
<?php
if($opr=="upd")
{
$sql_upd=mysql_query("SELECT * FROM students WHERE stud_id=$id");
$rs_upd=mysql_fetch_array($sql_upd);
list($y,$m,$d)=explode('-',$rs_upd['dob']);
?>
答案 0 :(得分:0)
为什么要手动解析日期? PHP具有日期内置函数:
<?php
if($opr=="upd"){
$sql_upd = mysql_query("SELECT * FROM students WHERE stud_id=$id");
$rs_upd = mysql_fetch_array($sql_upd);
$dob = strtotime($rs_upd['dob']); // Convert into UNIX time
$y = date("Y",$dob); // Extract Year
$m = date("m",$dob); // Extract Month
$d = date("d",$dob); // Extract Day
echo "Day : ".$d."\n";
echo "Month : ".$m."\n";
echo "Year : ".$y."\n";
}
?>