注意:未定义索引:在 C:\wamp\www\somygms\a.php 中的第 142 行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10309322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Notice: Undefined index: in C:\wamp\www\somygms\a.php on line 142
提问by admin
I got an error whenever I run this php code on my local web server:
每当我在本地 Web 服务器上运行此 php 代码时,都会出现错误:
<?php
@ require_once ('C:\wamp\www\Connections\koneksi.php');
session_start();
if (!isset($_SESSION['id']))
{
header("Location:index.php");
}
$sql = "SELECT * FROM pasien WHERE noreg = 1122312131";
$query = mysql_query($sql) or die(mysql_error());
$data2 = mysql_fetch_array($query);
?>
<form id="form1" name="form1" method="post" action="#">
<table width="804" border="0" id="inputdata" style="border-collapse:collapse">
<tr>
<th width="8" rowspan="3" bgcolor="#CCCCCC" scope="row"> </th>
<th width="104" height="50" bgcolor="#CCCCCC" scope="row"><div align="right">Kode Pasien</div></th>
<td width="250" bgcolor="#CCCCCC"><label for="nama"></label>
<label for="noreg"></label>
<div align="left">
<input name="noreg" type="text" id="noreg" size="15" maxlength="13">
<input type="submit" name="view" id="view" value="View"> <?php
@ include_once ('database.php');
$view = $_POST['view'];
$noreg = $_POST['noreg'];
if($view){
$_POST[$noreg];
}
?>
This is the error:
这是错误:
( ! ) Notice: Undefined index: view in C:\wamp\www\somygms\a.php on line 139
and
和
( ! ) Notice: Undefined index: noreg in C:\wamp\www\somygms\a.php on line 140
Thanks for any help, will be appreciated.
感谢您的帮助,将不胜感激。
-admin
-行政
回答by Starx
You are initializing those two variables with the array item does not exists.
您正在使用不存在的数组项初始化这两个变量。
$view = $_POST['view'];
$noreg = $_POST['noreg'];
Clearly shows that the viewand noregare not coming from the POST method. You should check to confirm this. Use var_dump($_POST);to see the posted data.
清楚地表明view和noreg不是来自 POST 方法。您应该检查以确认这一点。用var_dump($_POST);看发布的数据。
When you are coding, you should make sure that the code you are writing will execute on all cases as much as possible. In your case, initialize the variables before or use isset to check and initialize again.
在编码时,您应该确保您编写的代码尽可能在所有情况下都能执行。在您的情况下,请先初始化变量或使用 isset 再次检查和初始化。
$view = isset($_POST['view']) ? $_POST['view'] : '';
$noreg = isset($_POST['noreg']) ? $_POST['noreg'] : '';
Now that it is being pointed out.... The page by default will have *no POST variables *, so you have filter such cases out
现在它被指出了......默认情况下该页面将具有*no POST variables *,因此您已将此类情况过滤掉
if(isset($_POST) && count($_POST)) {
@ include_once ('database.php');
$view = $_POST['view'];
$noreg = $_POST['noreg'];
if($view){
$_POST[$noreg];
}
}
回答by KOUAME
Call to a member function fetch()on a non-object in C:\wamp\www\chat\chat_vue.phpon line 3
在第 3 行调用fetch()非对象C:\wamp\www\chat\chat_vue.php上的成员函数
回答by Menztrual
Its because of you accessing a key in $_POST that doesnt exist. Try the following:
这是因为您访问了 $_POST 中不存在的密钥。请尝试以下操作:
$view = (isset($_POST['view']) ) ? $_POST['view'] : '';
$noreg = (isset($_POST['noreg']) ) ? $_POST['noreg'] : '';

