Hi guys,

I have a small problem here...
There is a customer id field and a search button in one page.

In my database there is a table called "customer" which contains fields of customer_id, full_name, name_with_initials, address, contact_number and gender. The table is filled with record of each customer separately.

I want something likes this to be done. If the user selects customer id 1 and click on search button the details of that customer should appear for the verifying purposes. How this could be done in php?

Thanks,
Heshan.

@chrishea, thanks for your tutorial.

I have made a search, but it does not provide an output. Instead it outputs a blank customer detail form. Anyone can help me out to find the error.....

<?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
           if(isset($_POST['customer_id'])){ 
	        $customer_id=$_POST['customer_id']; 
		   		   
           $query = "select * from customer where customer_id=" .$customer_id;
		   $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="30"   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 width="50%" 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>          
          <td width="50%" class="attribute1" align="left">&nbsp;</td>
            
            <br />
          </p></td>
          <td width="2%">&nbsp;</td>
        </tr>
        
      </table>
      <p align="center">&nbsp;</p>
      <p align="center">
        <label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </label>
        <label>
          <input name="button" type="submit" id="button"  value="Approve Account"  />
          &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,

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.