Jump to content

Recommended Posts

Hi guys,

 

I want a search to be done.

 

That is when the user type the relevant customer id and clicks on search button the details of the customer should appear in a form. Therefore i tried the following code but it generates an empty form.

 

All the customer details were stored in the database under customer table.

customer(customer_id, full_name, name_with_initials, address, contact_number, gender)

 

Can anyone show me where i went wrong?

 

 

<?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> </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="<?php echo $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="30"   class="attribute1" value="<?php echo $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 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%"> </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%"> </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="<?php echo $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" id="jumpMenu" >
          <option selected="selected"><?php echo $row['gender']; ?></option>
            
            <option>Male</option>
            <option>Female</option>
          </select>          
          <td width="50%" class="attribute1" align="left"> </td>
            
            <br />
          </p></td>
          <td width="2%"> </td>
        </tr>
        
      </table>
      <p align="center"> </p>
      <p align="center">
        <label>      </label>
        <label>
          <input name="button" type="submit" id="button"  value="Approve Account"  />
                </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>

 

 

Thanks,

Your closing } that is part of your while(){ loop is located before the code that displays the information from the database. You would probably want to put that } at the end of the code that displays the information from the database so that the code would actually be executed each time through the loop.

Try:

<?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> </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="<?php echo $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="30"   class="attribute1" value="<?php echo $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 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%"> </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%"> </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="<?php echo $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" id="jumpMenu" >
          <option selected="selected"><?php echo $row['gender']; ?></option>
            
            <option>Male</option>
            <option>Female</option>
          </select>          
          <td width="50%" class="attribute1" align="left"> </td>
            
            <br />
          </p></td>
          <td width="2%"> </td>
        </tr>
        
      </table>
      <p align="center"> </p>
      <p align="center">
        <label>      </label>
        <label>
          <input name="button" type="submit" id="button"  value="Approve Account"  />
                </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
}
   }
   ?>
      

I'm just trying to understand exactly what you want this page to do.

 

Say someone comes to the page, but has not submitted a POST['customer_id'].  Do you want them to see a blank page, or an empty form?

 

Your code in your first post would result in a blank form if there is no customer_id set, and also a blank form if there IS a customer_id set.

 

The code suggested by jcbones would result in a blank page (no form or anything) if there is no customer_id, and a form populated with data from your database if there IS a customer_id.

 

 

Are either of those what you are going for?  Or do you want it to display a blank form if there's no customer_id, and a filled out form if there is one?

 

In either case, it sounds like you have another problem somewhere.  Do some tests to make sure that the $_POST['customer_id'] variable is actually being passed to the page (just put an echo $_POST['customer_id'] somewhere and see if it displays the correct information).  It could be a problem with not being connected to the database, or it could be a misnamed variable.  Check those things first.

@hoogie,

 

I have a customer details form. It includes Full name, Name with initials, address, contact number and gender of the customer. As soon as the user fills the customer details form the data should be stored in the customer table.

 

customer_id is the primary key of the "customer" table and it is set to be auto incremented.

 

When supervisor logged in he wants to check all the records. Therefore he should be able to do the search with customer_id.

$result = mysql_query($query) or die(mysql_error());
//Add the following lines:
if(mysql_num_rows($result) < 1) {
echo 'The record could not be found.';
//to end the script un-comment the next line:
//exit();
}

 

 

Yeah, it resulted an empty form.

 

This the whole coding. please check and see there may be some errors....

 

<?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']; 
		echo $_POST['customer_id'];
	   		   
           $query = "select * from customer where customer_id=" .$customer_id;
	   $result = mysql_query($query) or die(mysql_error());
	   if(mysql_num_rows($result) < 1) {
               echo 'The record could not be found.';
	   
	   while ($row=mysql_fetch_array($result)){
		   
		   
               if(mysql_num_rows($result) < 1) {
               echo 'The record could not be found.';
	   
	   
	   
  ?>
      
        <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="<?php echo $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="30"   class="attribute1" value="<?php echo $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 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%"> </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%"> </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="<?php echo $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" id="jumpMenu" >
          <option selected="selected"><?php echo $row['gender']; ?></option>
            
            <option>Male</option>
            <option>Female</option>
          </select>          
          <td width="50%" class="attribute1" align="left"> </td>
            
            <br />
          </p></td>
          <td width="2%"> </td>
        </tr>
        
      </table>
      <p align="center"> </p>
      <p align="center">
        <label>      </label>
        <label>
          <input name="button" type="submit" id="button"  value="Approve Account"  />
                </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
 }     
	  }
	   	  }
	         }
			 exit();
	   ?>
      
    </table>
  </form>
</div>
<img src="../images/mahapitiya 1.jpg" width="1024" height="139" />
</body>
</html>

 

Thanks,

Ok, I'm bored.  Let's do this.

 

First of all, you need to test to see if your id number is coming through.  Make a backup of this form we've been working on so you can restore it later if you need to.  Then erase everything in there and just put in this code:

<?php echo $_POST['customer_id']; ?>

 

Now try it out and see if it displays the id number.  If you submitted the form with the id number, and this page is blank, or gives you an error message, then you know that the problem is not with this page, but with the page that is submitting the customer_id.  Open that page instead and make sure that your inputs have the correct names and values.

 

Once you are SURE that the customer_id is coming through correctly, and has the correct name, this is the way I would write this page:

<?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
      
      //initilize variables
      
      $var_nic = '';
      $var_full_name = '';
      $var_name_with_initials = '';
      $var_address = '';
      $var_contact_number = '';
      $var_gender = '';
      
      
           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());
	   
	   if(mysql_num_rows($result) < 1) {
               echo 'The record could not be found.';
               }
       else {   
	   while ($row=mysql_fetch_array($result)){
	   
	   // replace blank variables with variables from the database
	   
	  $var_nic = $row['nic'];
    		  $var_full_name = $row['full_name'];
    		  $var_name_with_initials = $row['name_with_initials'];
    		  $var_address = $row['address'];
    		  $var_contact_number = $row['contact_number'];
    		  $var_gender = $row['gender'];  
	   }
             }
} 
	  
  ?>
      
        <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="<?php echo $var_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="30"   class="attribute1" value="<?php echo $var_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 width="50%" class="attribute1" align="left"><input type="text" name="name_with_initials" size="30"   class="attribute1" value="<?php echo $var_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" id="textarea" cols="45" rows="5"><?php echo $var_address; ?></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="<?php echo $var_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" id="jumpMenu" >
          <option selected="selected"><?php echo $var_gender; ?></option>
            
            <option>Male</option>
            <option>Female</option>
          </select>          
          <td width="50%" class="attribute1" align="left"> </td>
            
            <br />
          </p></td>
          <td width="2%"> </td>
        </tr>
        
      </table>
      <p align="center"> </p>
      <p align="center">
        <label>      </label>
        <label>
          <input name="button" type="submit" id="button"  value="Approve Account"  />
                </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>      
    </table>
  </form>
</div>
<img src="../images/mahapitiya 1.jpg" width="1024" height="139" />
</body>
</html>

 

This should make it so you see a form no matter how you get to the page, but if you get to the page with an id number, it will pull the data and populate the form.  Otherwise the form will be blank.

 

I didn't test it so I might have forgotten a ; here or there.  I always do that.

The output will display as a blank form... :( :(

 

This is how entered data to the database. But i have done it using object based php. I think there is no impact on that. The customer table is populated with relevant data.

 

<?php

include 'validateCustomer.php';


$nic= $_POST['nic'];
$full_name= $_POST['full_name'];
$name_with_initials= $_POST['name_with_initials'];
$address= $_POST['address'];
$contact_number= $_POST['contact_number'];
$gender=$_POST['gender'];


$vm = new validateCustomer();
$vm -> customer($nic,$full_name,$name_with_initials,$address,$contact_number,$gender);

$db=mysql_connect("localhost","root","");
mysql_select_db("bank",$db) or 
   die ("could not select database");
   
  $result = mysql_query ("select max(customer_id) from customer",$db);
  $row=mysql_fetch_row($result);
  if (!$row[0])
  $x=0;
  else
  $x=$row[0]; 

  $x+=1;
  $s_id=$x;
  
  
  




?>

 

ValidateCustomer.php page looks like this.

 

<?php
include 'dbconnection.php';
class validateCustomer{
public function customer($nic,$full_name,$name_with_initials,$address,$contact_number,$gender){
$con = new DBConnect();
$db = $con->getDB();
$result = mysql_query ("select max(customer_id) from customer",$db);
$row=mysql_fetch_row($result);
if (!$row[0])
$x=0;
else
$x=$row[0]; 

$x+=1;
$s_id=$x;

mysql_query("INSERT INTO customer(nic,full_name,name_with_initials,address,contact_number,gender) VALUES ('$nic','$full_name','$name_with_initials','$address','$contact_number','$gender')",$db);
}
}
?>

I don't think the problem is the way the data is put into the database, I think the problem is with the page that sends the customer_id to your form form.

 

This is POST data, right?  Which means that there is another page with a form that has an input named "customer_id", and when you submit that form, it takes you to this page that we're working on.  Does that make sense?  I think we need to look at the code that is sending the customer_id, not the page that is receiving it.

@ hoogie,

 

customer_id is the primary key of customer table and it was set to be auto incremented. But there is no separate form which submits customer_id. This is the structure of the customer table.

  customer (customer_id, full_name, name_with_initials, address, contact_number, gender)

 

When the supervisor wants to search the records of customer table, he should be able to do it with the use of customer_id..... 8)

@ hoogie,

 

customer_id is the primary key of customer table and it was set to be auto incremented. But there is no separate form which submits customer_id. This is the structure of the customer table.

  customer (customer_id, full_name, name_with_initials, address, contact_number, gender)

 

When the supervisor wants to search the records of customer table, he should be able to do it with the use of customer_id..... 8)

 

I understand this.  I'm not communicating very well.

 

What I'm asking has nothing to do with the database.

 

Maybe a better way of asking the question is, say the supervisor wants to look up records for the id number 55514.  Where does he type in "55514" to see if there are any matches?  Is it somewhere on this page, or is it on another page?

The supervisor page has a link " Approve Account". When he clicks on that link there is a page that appears a form. It includes that customer ID and search button.

 

When he types a customer ID and clicks on search button that relevant record should appear.

The action of this form is the one we are working with... 8)

This is that form.....

 

<!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">
<!--
body,td,th {
font-size: 18px;
}
-->
</style></head>

<body>

<p><img src="../images/mahapitiya 1.jpg" width="1024" height="139" />
</p>
<p> </p>
<p> </p>
<p> </p>
<p>
  <label>Customer ID </label>
  <label>
    <input type="text" name="textfield" id="textfield" />
  </label>
</p>
<form id="form1" name="form1" method="post" action="approve_account.php">
  <label>
    <input type="submit" name="button" id="button" value="Search" />
  </label>
</form>
<p> </p>
<p>   </p>
</body>
</html>

Hi

 

You have no input field called customer_id so $_POST['customer_id']  won't be populated. Your only real input field is called textfield (so would be $_POST['textfield']) but that isn't part of the form (it is a couple of lines before the start of the form).

 

All the best

 

Keith

Kickstart is right.  The problem is with this page, not the one we were looking at originally.

 

Your input needs to be inside of your <form> tags otherwise it's not included in the form.  And the name of the input is the name of the variable that's passed.  So your input named 'textfield' becomes $_POST['textfield'].  If you want to use $_POST['customer_id'] instead, you need to rename this input to 'customer_id'.

 

Your code should look something like this (starting at the body tag)

 

<body>

<p><img src="../images/mahapitiya 1.jpg" width="1024" height="139" />
</p>
<p> </p>
<p> </p>
<p> </p>
<p>
<form id="form1" name="form1" method="post" action="approve_account.php">
  <label>Customer ID </label>
  <label>
    <input type="text" name="customer_id" id="textfield" />
  </label>
</p>
  <label>
    <input type="submit" name="button" id="button" value="Search" />
  </label>
</form>
<p> </p>
<p>   </p>
</body>
</html>

Thank you kickstart and hoogie, i have corrected my mistakes in the form.

 

But it still gives an empty form...

 

However it outputs the message that " record cannot be found" when supervisor tries to search for a customer_id which is not in the database.

Now this is my whole code.....

 

<!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">
<!--
body,td,th {
font-size: 18px;
}
-->
</style></head>

<body>

<p><img src="../images/mahapitiya 1.jpg" width="1024" height="139" />
</p>
<p> </p>
<p> </p>
<p> </p>
<p>
<form id="form1" name="form1" method="post" action="approve_account.php">
  <label>Customer ID </label>
  <label>
    <input type="text" name="customer_id" id="textfield" />
  </label>
</p>

  <label>
    <input type="submit" name="button" id="button" value="Search" />
  </label>
</form>
<p> </p>
<p>   </p>
</body>
</html>

 

This is the other coding..

 

<?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
  
   
      
      //initilize variables
      
      $var_nic = '';
      $var_full_name = '';
      $var_name_with_initials = '';
      $var_address = '';
      $var_contact_number = '';
      $var_gender = '';
  
           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());
	   
	     if(mysql_num_rows($result) < 1) {
               echo 'The record could not be found.';
	   
	     while ($row=mysql_fetch_array($result)){
		   
		   
               if(mysql_num_rows($result) < 1) {
               echo 'The record could not be found.';
		   }
		   else{
			    while ($row=mysql_fetch_array($result)){

			 // replace blank variables with variables from the database

	             $var_nic = $row['nic'];
                     $var_full_name = $row['full_name'];
                     $var_name_with_initials = $row['name_with_initials'];
                     $var_address = $row['address'];
                     $var_contact_number = $row['contact_number'];
                     $var_gender = $row['gender'];
				}
				}
		   }
		 }
		 }
	   
	   
  ?>
      
        <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="<?php echo $var_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="30"   class="attribute1" value="<?php echo $var_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 width="50%" class="attribute1" align="left"><input type="text" name="name_with_initials" size="30"   class="attribute1" value="<?php echo $var_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" id="textarea" cols="45" rows="5"><?php echo $var_address; ?></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="<?php echo $var_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" id="jumpMenu" >
          <option selected="selected"><?php echo $var_gender; ?></option>
            
            <option>Male</option>
            <option>Female</option>
          </select>          
          <td width="50%" class="attribute1" align="left"> </td>
            
            <br />
          </p></td>
          <td width="2%"> </td>
        </tr>
        
      </table>
      <p align="center"> </p>
      <p align="center">
        <label>      </label>
        <label>
          <input name="button" type="submit" id="button"  value="Approve Account"  />
                </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>
    
      
    </table>
  </form>
</div>
<img src="../images/mahapitiya 1.jpg" width="1024" height="139" />
</body>
</html>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.