PHP Registration form-Part 4


This post is the Continuation of the php registration form part 3. Here i’m going to explain the admin panel for the registration page alone so i’m not going to have the login panel for the admin section.

Here i’m going to create a new php page name as view.php. so In that page i will going to display the values that stored in the database from the registration page so we as a admin user i will perform two more operations edit the data and delete it from the view page itself.

please open view.php in some editor type the below code

<?php
$con = mysql_connect(“localhost”,”root”,””);
if (!$con)
  {
  die(‘Could not connect: ‘ . mysql_error());
  }

mysql_select_db(“login”, $con);

$result = mysql_query(“SELECT * FROM user_details”);

echo “<table border=’1′>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Password</th>
<th>Contant No</th>
</tr>”;

while($row = mysql_fetch_array($result))
  {
  echo “<tr>”;
  echo “<td>” . $row[‘first_name’] . “</td>”;
  echo “<td>” . $row[‘last_name’] . “</td>”;
  echo “<td>” . $row[‘Email’] . “</td>”;
  echo “<td>” . $row[‘Password’] . “</td>”;
  echo “<td>” . $row[‘Contact_no’] . “</td>”;
  echo “<td><a href=’edit.php?em=”.$row[‘Email’].”‘>” . edit . “</a></td>”;
  echo “<td><a href=’delete.php?em=”.$row[‘Email’].”‘>” . Delete . “</a></td>”;
  echo “</tr>”;
  }
echo “</table>”;

mysql_close($con);
?>

From my previous parts of this post. you can know about how  to connect the database with that file. so here i’m doing the same thing but storing that connection in a variable $con  After that i’m selecting the database name in the next sql statement.

Now i’m going to display the data from the database so for that we have to use the select query Statement. Syntax for select query is

select * from tablename;

so it will fetches all data from that table.If you want to select a particular data from the table means use where clause statement.

SELECT column_name(s)
FROM table_name;

so i need to display all data from the database so i preferred the first sql statement after i executed the query i will store that in a variable called $result. so the query is executed but i have to display the values.I will go with the table structure display of the data so i created table with normal html tags which will have an echo statement before that one because we are using the code in Php syntax.

<th>- table heading <td>-table definition so we have to display the fetched data in <td> so here im assigning the query to other variable for while condition to fetch the values in the <td>.$row[‘fieldname in the table’].</td> where row is the variable is assigned in the while loop.while loop is used to fetch all the records one by one  in the table structure. the two d0ts used in the front and end to separate the values. the final two <td> tags are  for the purpose of edit and delete operation of the record.for now use # for the href attribute instead of the link provided. Thats it all the database information will be displayed in view.php as a table structure will see about edit and delete function of the records in the Next part of this post.

 

Advertisements
About

Working For Cause Not For Applause

Tagged with: , , , , ,
Posted in PHP, web

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: