Hi,
I want to retrieve data from my database and display it in my form.
How can i do that? i mean the php coding of the process.
Thanks,
Heshan.
$sql = "SELECT WhatYouWant FROM NameOfTable WHERE id='Something you are searching for'";
$query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_object($query);
$id = htmlspecialchars($row->id);
echo "$id";
Hi There is 5 steps to this. here they are. good luck :)
1. connect to mysql
2.select the db
3.run mysql query
4.user data return
5. close database connection.
Hi,
I have a form containing customer details.Once user(Junior staff member) has clicked on "Open Account" button the data has been saved in the database.
Therafter when a supervisor logged in he should be able to verify the customer details.Therefore he should be able to view the details before he verifies.I want data to be displayed in a seperate form with different text fields.
Furthermore i also want to know how he can modify customer details if some mistakes done by the junior staff member.
Thanks,
Heshan.
hello heshanm, could you post some codes to use us that you are attempting to do this as well. Then if you have any errors or you are stuck we will help you to edit your code and guide you in the right directions.
This is the code for retrieving data.
<?php
$connect=mysql_connect("localhost","root","");
mysql_select_db("bank",$connect) or
die ("could not select database");
$query = "select * from customer";
$result = mysql_query($query) or die(mysql_error());
while ($row=mysql_fetch_array($result)){
$nic = $row['nic'];
$full_name = $row['full_name'];
$name_with_initials = $row['name_with_initials'];
$address = $row['address'];
$contact_number = $row['contact_number'];
$gender = $row['gender'];
echo $nic."<br> ".$full_name."<br> ".$name_with_initials."<br> ".$address."<br> ".$contact_number."<br> ".$gender."<br>";
}
?>
This works perfectly. I want this to be included with my text boxes in the form.
Here is some fields of the form.
<tr height="30">
<td width="2%" height="35"> </td>
<td width="43%" class="title02" align="left">National ID</td>
<td width="53%" class="attribute1" align="left">[B]<input type="text" name="nic" size="30" class="attribute1" />[/B]</td>
<td width="2%"> </td>
</tr>
<tr height="30">
<td height="33"> </td>
<td width="43%" class="title02" align="left">Full Name</td>
<td width="53%" class="attribute1" align="left">[B][B]<input type="text" name="full_name" size="50" class="attribute1" />[/B][/B]</td>
<td width="2%"> </td>
</tr>
How these lines will modify in order to include data to the text boxes??
Thanks,
Heshan.
use like this.
<input type="text" name="nic" size="30" class="attribute1" value="<?=$nic?>" />
I tried that.
The same value of "<?=$nic?>" will come as it is inside the text boxes.
The above code i mentioned list the values nicely. But these values are not entered to the text boxes in my form. I think that my code will also has to be changed according to your coding.
Can you say what are the modifications that need to be done to my above code?
Thanks,
Heshan
post your full code i will change
I posted the full code already. The above code is the one i tried. There may be some additions to do it that i do not know.
Thanks,
Heshan
ok....this is the code
<?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=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<table>
<?
$query = "select * from customer";
$result = mysql_query($query) or die(mysql_error());
while ($row=mysql_fetch_array($result)){
?>
<tr height="30">
<td width="2%" height="35"> </td>
<td width="43%" class="title02" align="left">National ID</td>
<td width="53%" class="attribute1" align="left"><input type="text" name="nic" size="30" class="attribute1" value="<?=$row['nic']?>"/></td>
<td width="2%"> </td>
</tr>
<tr height="30">
<td height="33"> </td>
<td width="43%" class="title02" align="left">Full Name</td>
<td width="53%" class="attribute1" align="left"><input type="text" name="full_name" size="50" class="attribute1" value="<?=$row['full_name']?>" /></td>
<td width="2%"> </td>
</tr>
<?
}
?>
</table>
</body>
</html>
@ muralikalpana, thanks for your continuous support. I need little more help. I have tried your coding, but it is not working. Here is it....
<?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> </td>
<td class="title02"> </td>
<td> </td>
<td> </td>
</tr>
<tr height="30">
<td width="2%" height="35"> </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%"> </td>
</tr>
<tr height="30">
<td height="33"> </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%"> </td>
</tr>
<tr height="30">
<td height="34"> </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%"> </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%"> </td>
</tr>
<tr height="30">
<td width="2%"> </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%"> </td>
</tr>
<tr height="30">
<td width="2%"> </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%"> </td>
</tr>
</table>
<p align="center"> </p>
<p align="center">
<label>
<input name="button" type="submit" id="button" value="Approve Account" />
</label>
<label>
<input name="button" type="submit" id="button" value="Modify" />
</label>
<label> <a href="accsup_help.php">
<input name="button" type="submit" id="button" value="Help" />
</a></label>
</td>
</p>
</fieldset>
<td width="5%"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td align="center"> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><font color="red" size="1" ></font></td>
<td> </td>
</tr>
<?php
}
?>
</table>
</form>
</div>
<img src="../images/mahapitiya 1.jpg" width="1024" height="139" />
</body>
</html>
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.