Reader Level:
ARTICLE

Display Records in HTML TextBoxes in PHP Script

Posted by Sharad Gupta Articles | PHP April 18, 2013
This article explains how to handle HTML related applications with use of PHP scripts as well as how to manage MySQL database table data with HTML and PHP scripts.
  • 0
  • 0
  • 14311
Download Files:
 

Introduction

The main purpose of this article is to explain to you how to handle HTML related applications with use of PHP scripts as well as how to manage MySQL database table data with HTML and PHP scripts. Basically in this article, I am presenting the concept of searching Bank Account details. If I say account details, then what will come to mind? Basically we require a unique account number of the user, and on the behalf of this account number; a bank employer determines the details of this account number user.

So first I design a simple form using HTML and PHP scripts for taking an account number as input to determine the entire details of the corresponding user.

Design Script

In this script, I am using one HTML TextBox and a submit button, the TextBox is responsible for accepting the account number and the button submits this page value to the next page, that is specified in the HTML form tag and  I also set the table background image. Now you can easily write the script and save it into the www root directory with the name of "fill.php", such as I do.

<html>

<body>

<form action="search.php" method="post">

 

   <table style="color:purple;border-style:groove; height:150px;width:350px" background="backimage.jpg">

            <tr>

                <td style=" height:25px; font-family:'Copperplate Gothic Bold'">&nbsp;</td>

            </tr>

            <tr>

                <td style="color:red;background-color:aqua;height:25px">Enter Account no&nbsp;&nbsp;&nbsp;&nbsp;

                    <input name="name" id="name" type="text"/></td>

            </tr>

            <tr>

                <td style="height:25px">nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                           <input type="submit" value="Submit" style="color:white;background-color:brown; height:30px" /></td>

            </tr>

        </table>

</form>

</body>

</html>

Output

search-form.gif

Now after the compilation of the "fill.php" page, simply write the account number and click on the submit button. That will redirect to the new page named "serach.php", and this form displays all the information about the corresponding account number user. 

I first show you how to design a MySQL database table related to user account details. Here I show you an image of the database table with values filled in, using this you can design your account details table.

database-table-design.gif

After the database design, I will now tell you how to design a form to display all the details of the user that are fetched from a MySQL database table as determined by an account number.  I added a script here so in this code I simply retrieve data from the MySQL database, and that code I wrote within the PHP script. In the query:

"select * from accoundtl where account_no='$_POST[name]'
";

$_POST[name] accepts the account number from the "fill.php" page TextBox. So it easily compares with the column "account_no" of the "accountdtl" table and returns the corresponding matching values. The returned result accepts using the "musql_fetch_array()" function, and this returns the result that is accepted individually (in other words each column's value) accepts by the variables. So completing it, let's talk about the HTML design part, so in this part I use a number of textboxes for accepting those column values, that are stored in the PHP variables using this code:

<input id="Text1" type="text" value='<?php echo  $accountnumber; ?>'/>

The TextBox code declared above simply displays the table column values, that are previously stored in the PHP variables. And it does it all with textboxes, which are defined below.

Code

<?php

$con = mysql_connect("localhost","root","");

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

mysql_select_db("mysql", $con);

$con = mysql_connect("localhost","root","");

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

mysql_select_db("mysql", $con);

//$sql="select * from accountdtl";

$result = mysql_query("select * from accountdtl where account_no='$_POST[name]'");

while($rowval = mysql_fetch_array($result))

 {

$accountnumber= $rowval['account_no'];

$title= $rowval['title'];

$fname= $rowval['fname'];

$lname= $rowval['lname'];

$add1= $rowval['address1'];

$add2= $rowval['address2'];

$town= $rowval['town'];

$country= $rowval['country'];

$pin= $rowval['pcode'];

$mob= $rowval['con_no'];

$mailid= $rowval['mail_id'];

$uname= $rowval['uname'];

$balance= $rowval['balance'];

}

mysql_close($con);

 

?>

<html>

<body>

<from >

 

  <table  style="color:purple;border-style:groove; height:150px;width:350px" background="3.jpg">

        <tr>

           

            <td style="font-family:Copperplate Gothic Bold">&nbsp;</td>

        </tr>

        <tr>

            <td style="color:red;background-color:aqua;" class="auto-style3">Account no:</td>

            <td class="auto-style4">

                <input id="Text1" type="text" value='<?php echo  $accountnumber; ?>'/></td>

        </tr>

        <tr>

            <td style="color:red;background-color:aqua;" class="auto-style3">Title</td>

            <td class="auto-style4">

                <input id="Text2" type="text" value='<?php echo  $title; ?>'/></td>

        </tr>

        <tr>

             <td style="color:red;background-color:aqua;" class="auto-style3">FirstName:</td>

            <td class="auto-style4">

                <input id="Text3" type="text" value='<?php echo  $fname; ?>' /></td>

        </tr>

        <tr>

             <td style="color:red;background-color:aqua;" class="auto-style3">Surname:</td>

            <td class="auto-style4">

                <input id="Text4" type="text" value='<?php echo  $lname; ?>' /></td>

        </tr>

        <tr>

            <td style="color:red;background-color:aqua;" class="auto-style3">Address Line 1:</td>

            <td class="auto-style4">

                <input id="Text5" type="text" value='<?php echo  $add1; ?>' /></td>

        </tr>

        <tr>

           <td style="color:red;background-color:aqua;" class="auto-style3">Address Line 2:</td>

            <td class="auto-style4">

                <input id="Text6" type="text" value='<?php echo  $add2; ?>' ></td>

        </tr>

        <tr>

             <td style="color:red;background-color:aqua;" class="auto-style3">Town:</td>

            <td class="auto-style4">

                <input id="Text7" type="text" value='<?php echo  $town; ?>'/></td>

        </tr>

        <tr>

             <td style="color:red;background-color:aqua;" class="auto-style3">Country:</td>

            <td class="auto-style4">

                <input id="Text8" type="text" value='<?php echo  $country; ?>' /></td>

        </tr>

        <tr>

             <td style="color:red;background-color:aqua;" class="auto-style3">Post Code:</td>

            <td class="auto-style4">

                <input id="Text9" type="text"  value='<?php echo  $pin; ?>'/></td>

        </tr>

        <tr>

             <td style="color:red;background-color:aqua;" class="auto-style3">Contact Number:</td>

            <td class="auto-style4">

                <input id="Text10" type="text" value='<?php echo  $mob; ?>'/></td>

        </tr>

        <tr>

            <td style="color:red;background-color:aqua;" class="auto-style3">Email Address:</td>

            <td class="auto-style4">

                <input id="Text11" type="text" value='<?php echo  $mailid; ?>'/></td>

        </tr>

        <tr>

             <td style="color:red;background-color:aqua;" class="auto-style3">User Name:</td>

            <td class="auto-style4">

                <input id="Text12" type="text" value='<?php echo  $uname; ?>'/></td>

        </tr>

        <tr>

            <td style="color:red;background-color:aqua;" class="auto-style3">Balance:</td>

            <td>

                <input id="Text13" type="text" value='<?php echo  $balance; ?>' /></td>

        </tr>

        <tr>

            <td></td>

        </tr>

    </table>

</form>

</body>

</html>

Output

Fill in the account number corresponding to the search button

fill-account-no.gif


After clicking on the button, the output will look like:


display-table-data.gif

COMMENT USING

Trending up