How to view Table values in HTML webpage using php
Use the code below to view the table data.
view.php
<!DOCTYPE html>
<html>
<head>
<title>View Data</title>
</head>
<body>
<?php
include_once('config.php');
//Fetching all data (rows or tuples) from the student_details table
$query = "SELECT * FROM students_details";
//Executing the query
$result = mysql_query($query);
?>
<h1 align="center">View Data</h1>
<table border='1px' align="center" style="width:90%;">
<tr>
<th><center>Roll No</center></th>
<th><center>Name</center></th>
<th><center>Email</center></th>
<th><center>Address</center></th>
<th><center>Phone Number</center></th>
<th><center>Edit</center></th>
</tr>
<?php
//Using while loop iterating over the table to fetch all the rows data from table
while($row=mysql_fetch_assoc($result))
{
?>
<tr align="center">
<td><?php echo $row['roll_no']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['address']; ?></td>
<td><?php echo $row['phone_number']; ?></td>
<td><a href="Update.php?id=<?php echo $row['roll_no']; ?>">Edit</td>
</tr>
<?php
}
?>
</table>
</body>
</html>
config.php
<?php
//Database connection
$server = "localhost";
$usrename = "root";
$password = "";
$database = "handson_demo";
$conn = mysql_connect($server,$usrename,$password);
$db = mysql_select_db($database,$conn);
if (!$db) {
die("Database connection failed ! >> ".mysqli_connect_error());
}else
{
//echo "Database connection Success";
}
?>
<?php
// ---------------------------Update Profile --------------------------------------------------
if(isset($_POST['editprofile'])){
$roll_no= $_POST['roll_no'];
$name= $_POST['name'];
$email = $_POST['email'];
$address = $_POST['address'];
$phone_number = $_POST['phone_number'];
$q="UPDATE students_details SET
roll_no='$roll_no',
name='$name',
email='$email',
address='$address',
phone_number = '$phone_number'
WHERE roll_no='$roll_no'";
echo $q;
$result=mysql_query($q);
if($result){
echo "<script>alert('Profile updated Successfully!');</script>";
//echo "<script>location.href='50_myprofile.php';</script>";
}
else{
echo "<script>alert('Failed!');</script>";
//echo "<script>location.href='50_myprofile.php';</script>";
}
}
?>

Comments
Post a Comment