奇怪 ,$_POST[]取值报错,该怎么处理

WBOY
Release: 2016-06-13 13:44:44
Original
1255 people have browsed it

奇怪 ,$_POST[]取值报错
  $name=$_POST['name'];
  $password=$_POST['password'];
  if ((!isset($name)) || (!isset($password))) {
?>
 

Please Log In


 

This page is secret.


 

 

Username:


 

Password:


 


 

  } else {
  $mysql = mysqli_connect("localhost", "webauth", "123456");
  if(!$mysql) {
  echo "Cannot connect to database.";
  exit;
  }
  $selected = mysqli_select_db($mysql, "auth");
  if(!$selected) {
  echo "Cannot select database.";
  exit;
  }
  $query = "select count(*) from authorised_users where
  name = '".$name."' and
  password = '".$password."'";

  $result = mysqli_query($mysql, $query);
  if(!$result) {
  echo "Cannot run query.";
  exit;
  }
  $row = mysqli_fetch_row($result);
  $count = $row[0];
  if ($count > 0) {
  echo "

Here it is!


 

I bet you are glad you can see this secret page.

";
  } else {
  echo "

Go Away!


 

You are not authorized to use this resource.

";
  }
  }
?>

报错如下:Notice: Undefined index: name in C:\wamp\www\logindb.php on line 2
  Notice: Undefined index: password in C:\wamp\www\logindb.php on line 3
以前貌似没这个问题,重新装了个版本的WAMP,出现了这个问题,奇怪

------解决方案--------------------
不是错误
修改php.ini配置文件,error_reporting = E_ALL & ~E_NOTICE
------解决方案--------------------
修改php.ini配置文件,error_reporting = E_ALL & ~E_NOTICE 问题解决了

这种只是屏蔽了 E_NOTICE的显示,实际问题还是存在的,就好像掩耳盗铃一样,问题出现了,但你假装不知道而已。

if(!empty($_POST['submit']))
{
$name=$_POST['name'];
$password=$_POST['password'];
}

这才是正确的方法,在使用POST数据之前,事先就要对数据的正确性进行判断,连input是否存在都不知道,就贸然使用,在生产环境是不可接受的。
------解决方案--------------------
查看置顶的帖子里有基础问题里面说到你的问题了
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!