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

请问从数据库取出值然后报错的有关问题

WBOY
Release: 2016-06-13 11:56:26
Original
846 people have browsed it

请教从数据库取出值然后报错的问题。
第一段代码index.html

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

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