Home > Backend Development > PHP Tutorial > 请教从数据库取出值然后报错的问题。

请教从数据库取出值然后报错的问题。

WBOY
Release: 2016-06-23 13:57:40
Original
909 people have browsed it

第一段代码index.html

<html><head>	<title>管理员登录</title></head><body>	<form action="active.php" method="POST">	<table>		<tr>			<td>用户名:</td>			<td><input type="text" name="user"></td>		</tr>		<tr>			<td>密码:</td>			<td><input type="text" name="pass"></td>		</tr>		<tr>				<td rows="2"><input type="submit" value ="登录"></td>		</tr>	</table>	</form></body></html>
Copy after login

第二段代码active.php
<?php		$user=$_POST['user'];		$pass=$_POST['pass'];			$link=mysql_connect("localhost","root","");		$db=mysql_select_db("blog",$link);		mysql_query("set names utf8");		$sql="select * from user where username='$user'";		$result=mysql_query($sql);		while($row=mysql_fetch_row($result)){		$username=$row['username'];//用单引号就是不行。		$password=$row[2];		}echo $username;echo "<hr>";echo $password;?>
Copy after login


报错:

//$username = ""; 初始化该变量不行照样报错
//error_reporting(E_ALL ^ E_NOTICE);//屏蔽掉警告但是值却取不出来。

求:
该问题解决方法!对了,我使用的是WampServer Version 2.4


回复讨论(解决方案)

mysql_fetch_row()  从和指定的结果标识关联的结果集中取得一行数据并作为数组返回。每个结果的列储存在一个数组的单元中,偏移量从 0 开始。  只有数字的键值不存在字符串的键值
$username=$row['username'];//字符串username的键值是取不到值的
$password=$row[2];//数字键值能取到值

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