出现这样,怎么解决?Notice: Undefined index: type in D:\server\www\delete.php on line 9 yes or no
代码:<?php$db=mysql_connect('localhost','bp6am','bp6ampass')ordie('Unabletoconnect.Chec...
代码:
<?php
$db=mysql_connect('localhost','bp6am','bp6ampass') or
die ('Unable to connect.Check your connection parameters.');
mysql_select_db('moviesite',$db) or dir(mysql_error($db));
if (!isset($_GET['do']) || $_GET['do'] != 1) {
switch ($_GET['type']) {
case 'movie':
echo 'Are you sure you want to delete this movie?<br/>';
break;
case 'people':
echo 'Are you sure you want to delete this person?<br/>';
break;
}
echo '<a href="' . $_SERVER['REQUEST_URI'] . '&do=1">yes</a> ';
echo 'or <a href="admin.php">no</a>';
} else {
switch ($_GET['type']) {
case 'people':
$query = 'UPDATE movie SET
movie_ieadactor = 0
WHERE
movie_ieadactor = ' . $_GET['id'];
$result = mysql_query($query, $db) or die(mysql_error($db));
$query = 'DELETE FROM people
WHERE
people_id = ' . $_GET['id'];
$result = mysql_query($query, $db) or die(mysql_error($db));
?>
<p style="text-align: center;">Your person has been deleted.
<a href="movie_index.php">Return to Index</a></p>
<?php
break;
case 'movie':
$query = 'DELETE FROM movie
WHERE
movie_id = ' . $_GET['id'];
$result = mysql_query($query, $db) or die(mysql_error($db));
?>
<p style="text-align: center;">Your movie has been deleted.
<a href="movie_index.php">Return to Index</a></p>
<?php
break;
}
}
?> 展开
<?php
$db=mysql_connect('localhost','bp6am','bp6ampass') or
die ('Unable to connect.Check your connection parameters.');
mysql_select_db('moviesite',$db) or dir(mysql_error($db));
if (!isset($_GET['do']) || $_GET['do'] != 1) {
switch ($_GET['type']) {
case 'movie':
echo 'Are you sure you want to delete this movie?<br/>';
break;
case 'people':
echo 'Are you sure you want to delete this person?<br/>';
break;
}
echo '<a href="' . $_SERVER['REQUEST_URI'] . '&do=1">yes</a> ';
echo 'or <a href="admin.php">no</a>';
} else {
switch ($_GET['type']) {
case 'people':
$query = 'UPDATE movie SET
movie_ieadactor = 0
WHERE
movie_ieadactor = ' . $_GET['id'];
$result = mysql_query($query, $db) or die(mysql_error($db));
$query = 'DELETE FROM people
WHERE
people_id = ' . $_GET['id'];
$result = mysql_query($query, $db) or die(mysql_error($db));
?>
<p style="text-align: center;">Your person has been deleted.
<a href="movie_index.php">Return to Index</a></p>
<?php
break;
case 'movie':
$query = 'DELETE FROM movie
WHERE
movie_id = ' . $_GET['id'];
$result = mysql_query($query, $db) or die(mysql_error($db));
?>
<p style="text-align: center;">Your movie has been deleted.
<a href="movie_index.php">Return to Index</a></p>
<?php
break;
}
}
?> 展开
3个回答
展开全部
楼上的也对。
你这个是由于$_GET['type']未定义导致的Notice级别错误,最简单的方法就是设置一个默认值,例如,在你的程序开头添加如下一行即可,其余不需修改。
empty($_GET['type']) && $_GET['type'] = '默认值';
更多追问追答
追问
这个我也试过了,case 'movie':
echo 'Are you sure you want to delete this movie?';
break;
case 'people':
echo 'Are you sure you want to delete this person?';
这样这句话就没法显示了
追答
默认值这三个汉字改成 movie 或者 people
因为你的switch中没有default项,所以如果$_GET['type']既不是movie也不是people就无法显示任何一句话咯
展开全部
这种警告无所谓的
你要想不显示出来 修改一下 php的配置
修改php.ini
把error_reporting = E_ALL修改为error_reporting = E_ALL & ~E_NOTICE
重启apache
你要想不显示出来 修改一下 php的配置
修改php.ini
把error_reporting = E_ALL修改为error_reporting = E_ALL & ~E_NOTICE
重启apache
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这句改一下
$type = isset($_GET['type']) ? $_GET['type'] : '';
switch ($type) {
$type = isset($_GET['type']) ? $_GET['type'] : '';
switch ($type) {
更多追问追答
追问
还是不对哦!这样也不行
追答
现在还报什么错误?应该不是notice了吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询