我收到此错误 注意:未定义的索引:第60行的E:\ xampp \ htdocs \ index.php中的名称 这里有我的代码,请帮我摆脱这个错误。我是编码的新手
<?php
$root = '';
$path = 'images/';
$bhatti = array(
'1'=>'Katrina wants to meet you',
'2'=>'Kareena wants to meet you',
'3'=>'Aishwarya wants to meet you',
'4'=>'Shahrukh wants to meet you',
'5'=>'Aamir wants to meet you',
'6'=>'Shahid kapoor wants to meet you',
'7'=>'Parineeti wants to meet you',
'9'=>'Priyanka wants to meet you',
'10'=>'She wants to meet you',
'11'=>'Kristen wants to meet you',
'12'=>'Shriya wants to meet you',
'13'=>'Sonakshi wants to meet you',
'14'=>'Deepika wants to meet you',
'15'=>'Cameron wants to meet you',
'16'=>'Ajay wants to meet you',
'17'=>'wants to meet you',
'c'=>' wants to meet you'
);
$img = $bhatti[array_rand($bhatti,1)];
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="keywords" content="diabetes, about diabetes,alcohol and diabetes,heart attack,Rheums" />
<meta name="description" content="Click here to know the reason">
<meta property="og:description" content="<?php echo $img; ?>"/>
<meta property="og:type" content="article" />
<meta property="og:title" content="<?php echo $img; ?>" />
<meta property="og:image" content="http://<?php echo $_SERVER['SERVER_NAME']."/"; echo $path . rawurlencode($img); ?>.jpg" />
<meta property="og:image:width" content="300" />
<meta property="og:image:height" content="300" />
<meta property="og:image:type" content="image/jpg" />
</head>
<body>
<?php if($_GET['name']){ ?>
<div><img src="<?php echo $path . $img ?>.jpg" alt="" /></div>
<?php }else{?>
<div><img src="oops.png" alt="" /></div>
<?php } ?>
<p>Developed by <a href="https://www.Facebook.com/Ali42726"> Ali Hasan </a>.</p>
<p>Thank you for visiting </p>
</body>
</html>
我写这个是为了每次用户输入时显示一个随机图像,并将图像标题显示为页面名称。
答案 0 :(得分:0)
出错
<?php if($_GET['name']){ ?>
您需要检查名称是否在全局变量$ _GET中设置。
尝试使用
<?php if(isset($_GET['name'])){ ?>