是的,它连接到数据库,其他一切正常。我似乎无法从数据库中拉出传递,显示没有返回echo
<?php
$username="test";
include("db.php");
$con=mysql_connect($server, $db_user, $db_pwd) //connect to the database server
or die ("Could not connect to mysql because ".mysql_error());
mysql_select_db($db_name) //select the database
or die ("Could not select to mysql because ".mysql_error());
$query="select password from ".$table_name." where username='$username'";
$result=mysql_query($query,$con) or die('error');
while ($row = mysql_fetch_assoc($result));
$un_pass_s1=$row['password'];
echo $un_pass_s1;
?>
答案 0 :(得分:2)
while ($row = mysql_fetch_assoc($result));
循环,直到$row
为假。循环体是一个空的语句;
。您需要将访问$row
的代码放在循环中,而不是在循环之后。
答案 1 :(得分:0)
$sql=mysql_query("select password from ".$table_name." where username='$username'");
while($row=mysql_fetch_array($sql))
{
$un_pass_s1=$row['password'];
}
echo "value=".$un_pass_s1;