Home  >  Article  >  Backend Development  >  这个查询数据库的php为什么没有输出?

这个查询数据库的php为什么没有输出?

WBOY
WBOYOriginal
2016-06-20 12:46:38889browse

我是新手,写了一个查询mysql数据库的php,用post方式传递参数却没有输出,why?

close();		exit;	}	$query = "select * from sell where community = '".$community."'";	$result = $db->query($query);	$num = $result->num_rows;	if($num == 0) {		echo 'ERROR_NORESULT';	}	else {		for($i = 0; $i < num; $i++) {			$row = $result->fetch_assoc();			echo row['price'].' '.['area'];		}	}	$result->free();	$db->close();?>


回复讨论(解决方案)

11行 num_rows?
16行 $i

new mysqli的时候,传的主机名,用户名,密码,和数据库名,都是XXXX??

11行 num_rows?
16行 $i
笔误,16行是 $i

new mysqli的时候,传的主机名,用户名,密码,和数据库名,都是XXXX??


当然不是了,我也不好把帐户和密码给你打出来吧

close();		exit;	}	$query = "select * from sell where community = '".$community."'";	$result = $db->query($query);	$num = $result->num_rows;	if($num == 0) {		echo 'ERROR_NORESULT';	}	else {		for($i = 0; $i < $num; $i++) {			$row = $result->fetch_assoc();			echo row['price'].' '.['area'];		}	}	$result->free();	$db->close();?>

奇怪,变量名前面没有加 $ ,你的页面没有报错吗?
for($i = 0; $i             $row = $result->fetch_assoc();
             echo $row['price'].' '.$row['area'];
        }

奇怪,变量名前面没有加 $ ,你的页面没有报错吗?
for($i = 0; $i             $row = $result->fetch_assoc();
             echo $row['price'].' '.$row['area'];
        }


没有报错,一片空白。谢谢版主,太不小心了!

从你的代码看,每个分支都会有输出的
如果是一片空白,那就表示你测代码出现了致命错误,并且没有打开 php 的错误显示功能(自己给自己找麻烦)

也可以先 把$community = $_POST["community"];打印出来看看。

Statement:
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