代码:
<?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;
}
}
?>
楼上的也对。
你这个是由于$_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就无法显示任何一句话咯
改成movie了,这样我选择people的时候,输出的还是movie那一句提示,这个怎么解决
追答你选择people/movie的那个页面有问题吧。你直接在地址栏输入
[自行补全]/delete.php?type=people
看看提示是不是变了呢
如果默认值是movie的话,输入您上面的那个people地址后,输出的还是movie的那一句,还在有问题
追答留号码我远程你吧,这太费劲了
追问564871659
追答解决,最终原因是前置页面的url里面多了空格,?type =movie造成的
你要想不显示出来 修改一下 php的配置
修改php.ini
把error_reporting = E_ALL修改为error_reporting = E_ALL & ~E_NOTICE
重启apache
$type = isset($_GET['type']) ? $_GET['type'] : '';
switch ($type) {追问
还是不对哦!这样也不行
追答现在还报什么错误?应该不是notice了吧
追问但是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?';
这个switch的语句没有输出?怎么回事?
说明没有这两个选项呗,
多加一个默认的
case 'people':
echo 'Are you sure you want to delete this person?';
break;
default:
echo '#############';
break;
还是不能输出,只有yes和no