Hi,

I want to retrieve data from my database and display it in a particular form. The data should be displayed in text boxes. This is the coding that i have used. But it is not working. Can someone help me out......

<?php
$connect=mysql_connect("localhost","root","");
mysql_select_db("bank",$connect) or die ("could not select database");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
#apDiv4 {
	position:absolute;
	width:776px;
	height:598px;
	z-index:3;
	left: 206px;
	top: 300px;
}
#form1 {
	font-size: 18px;
	font-weight: bold;
}
body,td,th {
	font-size: 18px;
}
-->
</style>
</head>

<body>


   
<div id="apDiv4">
  <form action="" method="post" name="form1" id="form1">
    <fieldset>
      <legend class="cap"> Customer Details</legend>
      <table width="85%" height="350" border="0" align="center" cellpadding="5" cellspacing="0">
      <?php

           $query = "select * from customer";
           $result = mysql_query($query) or die(mysql_error());
           while ($row=mysql_fetch_array($result)){
			   
	  ?>
      
        <tr>
          <td>&nbsp;</td>
          <td class="title02">&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr height="30">
          <td width="2%" height="35">&nbsp;</td>
          <td width="46%" class="title02" align="left">National ID</td>
          <td width="50%" class="attribute1" align="left"><input type="text" name="nic" size="30"   class="attribute1" value="<?=$row['nic']?>" / ></td>
          <td width="2%">&nbsp;</td>
        </tr>
        <tr height="30">
        <td height="33">&nbsp;</td>
        <td width="46%" class="title02" align="left">Full Name</td>
        <td width="50%" class="attribute1" align="left"><input type="text" name="full_name" size="50" class="attribute1" value="<?=$row['full_name']?>"/ ></td>
          <td width="2%">&nbsp;</td>
        </tr>
        <tr height="30">
          <td height="34">&nbsp;</td>
          <td class="title02" align="left">Name With Initials</td>
          <td class="attribute1" align="left"><input type="text" name="name_with_initials" size="30" class="attribute1" value="<?=$row['name_with_initials']?>" /></td>
        </tr>
        <tr height="30">
          <td width="2%">&nbsp;</td>
          <td width="46%" class="title02" align="left">Address</td>
          <td width="50%" class="attribute1" align="left"><label>
            <textarea name="address" value="<?=$row['address']?>" id="textarea" cols="45" rows="5"></textarea>
          </label></td>
          <td width="2%">&nbsp;</td>
        </tr>
        <tr height="30">
          <td width="2%">&nbsp;</td>
          <td width="46%" class="title02" align="left">Contact Number</td>
          <td width="50%" class="attribute1" align="left"><input type="text" name="contact_number" size="30" class="attribute1" value="<?=$row['contact_number']?>" /></td>
          <td width="2%">&nbsp;</td>
        </tr>
        <tr height="30">
          <td width="2%">&nbsp;</td>
          <td width="46%" class="title02" align="left">Sex</td>
          <td width="50%" class="attribute1" align="left"><p>
            <select name="gender" value="<?=$row['gender']?>" id="jumpMenu" >
              <option selected="selected">Male</option>
              <option>Female</option>
            </select>
            <br />
          </p></td>
          <td width="2%">&nbsp;</td>
        </tr>
        
      </table>
      <p align="center">&nbsp;</p>
      <p align="center">
        <label>
          <input name="button" type="submit" id="button"  value="Approve Account"  />
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </label>
        <label>
          <input name="button" type="submit" id="button"  value="Modify"  />
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </label>
        <label> <a href="accsup_help.php">
          <input name="button" type="submit"  id="button"   value="Help"  />
        </a></label>
        </td>
      </p>
    </fieldset>
    <td width="5%">&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td align="center">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><font color="red" size="1" ></font></td>
      <td>&nbsp;</td>
    </tr>
    <?php
		   }
		   ?>
    </table>
  </form>
</div>
<img src="../images/mahapitiya 1.jpg" width="1024" height="139" />
</body>
</html>

Thanks,
Heshan.

Everything seems to be OK, except the

value="<?=$row['full_name']?>

; try using a simple echo statement

value="<? echo $row['full_name']; ?>

Maybe your PHP server isn't smart-echo-ok :)

I have tried it.But it is still not working. same thing between double quotes(" ") will appear in the text boxes. Like this...

<? echo $row['full_name']; ?>

What is the problem?

Thanks,
Heshan.

Oops; my mistake :D

<?php echo $row['full_name']; ?>

Hope this works.

Thank you very much. It works :-)

But there is a small issue. In the full name and address fields the entire value will not display.Only first part of the value will display. I think it is because i have added them by leaving spaces between each word of these fields.

Can u give me a solution to sought it out this problem....

Thanks,
Heshan.

It's probably (some 98.10%) that the $row doesn't match the field name in your database .. doublecheck ;)

They are ok.

I think the problem is with my way of entering values. I tried the full name "DulangaHeshan" instead of "Dulanga Heshan". Then it works.The space between 2 characters seems to be the problem. How can it solve?

Address is stored in a textarea in my form. Therefore it does not retrieve any data values. Same thing happen to my "gender" field also. It also not working.Is there a different way to retrieve data for these fields?

Earlier method was worked only for text boxes.Can you give a solution for this problem?

Thanks,
Heshan.

As for the TextArea, it doesn't support the Value attribute. You just have to write <TA>Your text</TA>. For the jumpmenu, you can't assign the default value in <select value"DEFAULT"></select>. You have to add another option (or check wheater or not one is selected. for the sake of simplicity, I'll be a repetition of value in my code).
You could check this code and thell me if the Space-Problem arises again ..

<?php
$connect=mysql_connect("localhost","root","");
mysql_select_db("bank",$connect) or die ("could not select database");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
#apDiv4 {
	position:absolute;
	width:776px;
	height:598px;
	z-index:3;
	left: 206px;
	top: 300px;
}
#form1 {
	font-size: 18px;
	font-weight: bold;
}
body,td,th {
	font-size: 18px;
}
-->
</style>
</head>

<body>


   
<div id="apDiv4">
  <form action="" method="post" name="form1" id="form1">
    <fieldset>
      <legend class="cap"> Customer Details</legend>
      <table width="85%" height="350" border="0" align="center" cellpadding="5" cellspacing="0">
      <?php

           $query = "select * from customer";
           $result = mysql_query($query) or die(mysql_error());
           while ($row=mysql_fetch_array($result)){
			   
	  ?>
      
        <tr>
          <td>&nbsp;</td>
          <td class="title02">&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr height="30">
          <td width="2%" height="35">&nbsp;</td>
          <td width="46%" class="title02" align="left">National ID</td>
          <td width="50%" class="attribute1" align="left"><input type="text" name="nic" size="30"   class="attribute1" value="<?php echo $row['nic']; ?>" / ></td>
          <td width="2%">&nbsp;</td>
        </tr>
        <tr height="30">
        <td height="33">&nbsp;</td>
        <td width="46%" class="title02" align="left">Full Name</td>
        <td width="50%" class="attribute1" align="left"><input type="text" name="full_name" size="50" class="attribute1" value="<?php echo $row['full_name']; ?>"/ ></td>
          <td width="2%">&nbsp;</td>
        </tr>
        <tr height="30">
          <td height="34">&nbsp;</td>
          <td class="title02" align="left">Name With Initials</td>
          <td class="attribute1" align="left"><input type="text" name="name_with_initials" size="30" class="attribute1" value="<?php echo $row['name_with_initials']; ?>" /></td>
        </tr>
        <tr height="30">
          <td width="2%">&nbsp;</td>
          <td width="46%" class="title02" align="left">Address</td>
          <td width="50%" class="attribute1" align="left"><label>
            <textarea name="address" id="textarea" cols="45" rows="5"><?php echo $row['address']; ?></textarea>
          </label></td>
          <td width="2%">&nbsp;</td>
        </tr>
        <tr height="30">
          <td width="2%">&nbsp;</td>
          <td width="46%" class="title02" align="left">Contact Number</td>
          <td width="50%" class="attribute1" align="left"><input type="text" name="contact_number" size="30" class="attribute1" value="<?php echo $row['contact_number']; ?>" /></td>
          <td width="2%">&nbsp;</td>
        </tr>
        <tr height="30">
          <td width="2%">&nbsp;</td>
          <td width="46%" class="title02" align="left">Sex</td>
          <td width="50%" class="attribute1" align="left"><p>
            <select name="gender"  id="jumpMenu" >
            <option selected="selected"><?php echo $row['gender']; ?></option>
              <option >Male</option>
              <option>Female</option>
            </select>
            <br />
          </p></td>
          <td width="2%">&nbsp;</td>
        </tr>
        
      </table>
      <p align="center">&nbsp;</p>
      <p align="center">
        <label>
          <input name="button" type="submit" id="button"  value="Approve Account"  />
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </label>
        <label>
          <input name="button" type="submit" id="button"  value="Modify"  />
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </label>
        <label> <a href="accsup_help.php">
          <input name="button" type="submit"  id="button"   value="Help"  />
        </a></label>
        </td>
      </p>
    </fieldset>
    <td width="5%">&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td align="center">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><font color="red" size="1" ></font></td>
      <td>&nbsp;</td>
    </tr>
    <?php
		   }
		   ?>
    </table>
  </form>
</div>
<img src="../images/mahapitiya 1.jpg" width="1024" height="139" />
</body>
</html>

The other problems are ok. Thank you for helping me out.

But the space problem is still there.....Any suggesstions??

Thanks,
Heshan.

Could you post you DB structure ? at least the full_name field.

Here is this.....

`customer_id` int(5) NOT NULL AUTO_INCREMENT,
`nic` varchar(15) NOT NULL,
`full_name` varchar(300) NOT NULL,
`name_with_initials` varchar(100) NOT NULL,
`address` varchar(500) NOT NULL,
`contact_number` varchar(15) NOT NULL,
`gender` varchar(10) NOT NULL,
PRIMARY KEY (`customer_id`)

For debugging purposes, try using this on line 64, and see if the problem persists:

<td width="50%" class="attribute1" align="left"><?php echo $row['full_name']; ?></td>

Just to figure out if the problem is DB related or just in the view part (even if I see NOTHING wrong with it ...)

And, for the sake of double-checking ... check if you have value="<? ?>" and not value=<? ?> on line64!!

<td width="50%" class="attribute1" align="left"><input type="text" name="full_name" size="50" class="attribute1" value=[B]"<?php echo $row['full_name']; ?>"[/B]/ ></td>
<td width="50%" class="attribute1" align="left"><?php echo $row['full_name']; ?></td>

The above code worl properly. Full name, Name with initials and gender fields were worked only after using the above code....

I have another problem. The process of my project goes like this. First an officer opens an account and thereafter supervisor verifies or modifies based on details. Then another record enters.......likewise continuous........

In this method if supervisor wants to check the second record in my customer table how he can access to this only?(retrieve that record details only)

Thanks for your support and hope you got a solution for this as well...

Heshan,

Btw, no space problem (did you check the "" ?) ?
Well, if you want to show one record, say, the second, use :

"select * from customer where customer_id=2"

Now there is no space problem. But when it attempts to display data in a text box the space problem arises. Otherwise its ok......

"select * from customer where customer_id=2"

This code cannot solve for every query since the supervisor keep checking records continuously.(1, 2, 3, 4, 5 etc) I want something general code which can be used to every record

+You haven't told me wheater or not you checked for the double quotes value=" ..." That's THE ONLY way to get such a problem :)
+Let's say you have a table displaying ALL the records you have;

+id+
|1 |        
|2 |
|3 |

you could make something like:

<a href="page.php?id=<?php echo $row['customerid']; ?>"><?php echo $row['customerid']; ?></a>

So when the user chooses an id, it jumps to page.php (ID info); in this page you'll have something like :

if(isset($_GET['id'])){
$id=$_GET['id'];
//EXECUTING YOU QUERY
$query="select * from customer where customer_id='$id'"

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.