PHP Read/Retrieve values from database
Step 1: First of all start your wamp/xampp server and open phpmyadmin tool normally available with both,
For this open http://localhost/phpmyadmin in your browser.
Step 2: Second click on databases tab and create a database with any name like testdb.
Step 3: Now click on Your Database name appeared under database tab of phpmyadmin and a new a table named members and add 4 colums.
Step 4 : write field name type and size and make id column as primary key and auto increment.
Step 5 : Open notepad and write below code in a new file and save in server root directory with php extension.
Example : readdb.php
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --><title>Bootstrap 101 Template</title><!-- Bootstrap --><!-- Latest compiled and minified CSS --><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/><!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --><!-- WARNING: Respond.js doesn't work if you view the page via file:// --><!--[if lt IE 9]><script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script><script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script><![endif]--></head><body><div class="container"><h1>Users List</h1><div class="row"><table class="table table-bordered table-hover table-striped"><tr><th>ID</th><th>Name</th><th>Email</th><th>Password</th></tr><?php$servername='localhost';$username='root';$passwd='';$dbname='jashan';$conn=mysqli_connect($servername,$username,$passwd,$dbname);$sql1="select * from members";$rs=mysqli_query($conn,$sql1);while($row=mysqli_fetch_array($rs)){?><tr><td><?php echo $row[0];?></td><td><?php echo $row[1];?></td><td><?php echo $row[2];?></td><td><?php echo $row[3];?></td></tr><?php}?></table></div></div></body></html>
Step 6 : open browser and see output http://localhost/readdb.php
No comments:
Post a Comment