1024programmer PHP Introductory example: Failed to read data from table in phpmysql, please give me some advice

Introductory example: Failed to read data from table in phpmysql, please give me some advice

Introductory example Failed to read data from table in php mysql, please give me some advice
1. Problem: I cannot read a table in mysql using php. Sometimes the page is blank, and sometimes there is a small section in php. I have been tinkering with the code for a day, please give me some guidance! Grateful! !
2. In mysql, database: test; table name: apple; (fields: firstname, lastname)
3.index.php (tried to connect to the database successfully)
Code:









<?php
$dbh = @mysql_connect("localhost","root","");
if(!$dbh){die("error");}
@mysql_select_db("test", $dbh);
$sql = "SELECT * FROM apple";
?>
<?
$rs = mysql_query($sql, $dbh);
while($row = mysql_fetch_array($rs))
echo $row[id];
echo $row[name];
echo '
';
?>
<?
@mysql_close($dbh);
?>




Please help me all heroes, thank you! !
——Solution——————–
Last of this post Edited by PhpNewnew on 2012-05-27 17:51:30
The log error is just a reminder that the default icon does not exist, it does not matter.

Read the code carefully
while($row = mysql_fetch_array($rs))
echo $row[id];
echo $row[name];
echo ‘
‘;
?>

Add upper brackets here

while($row = mysql_fetch_array($rs)) {
echo $row[id];
echo $row[name];
echo ‘
‘;
}
?>

Refresh after saving to see

In addition, you didn’t say that the database is
(Field: firstname,lastname)

How come $row[‘id’]? $row[‘name’]? came out

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/introductory-example-failed-to-read-data-from-table-in-phpmysql-please-give-me-some-advice/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索