我想使用php从mysql表中获取数据。请,谁能告诉我?这段代码有什么问题?什么是正确的代码,以从MySQL数据库获取数据:我怎样才能从数据库获取数据在PHP中使用MySQL?
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$connect=mysql_connect("localhost","root","");
// connect to databsase
mysql_select_db("form1",);
enter code here
// query the database
$query = mysql_query("SELECT * FROM users WHERE name = 'Admin' ");
// fetch the result/convert resulte in to array
WHILE ($rows = mysql_fetch_array($query)):
$rows = $rows['Name'];
$address = $rows['Address'];
$email = $rows['Email'];
$subject = $rows['Subject'];
$comment = $rows['Comment']
echo "$Name<br>$Address<br>$Email<br>$Subject<br>$Comment<br><br>";
endwhile;
?>
什么错误,你得到些什么? – amitchhajer 2013-02-12 07:19:19
您正在使用[an **过时的**数据库API](http://stackoverflow.com/q/12859942/19068)并应使用[现代替换](http://php.net/manual/en/ mysqlinfo.api.choosing.php)。 – Quentin 2013-02-12 07:19:59
当你使用'mysql_connect(“localhost”,“root”,“”);''时,声明上述变量的原因是什么?并告诉我们你从这段代码中得到的结果 – 2013-02-12 07:21:06