Hi all,

I have tried this for a very long time. But i could not found out the error. This should suppose to retrieve data when a user enters particular Account Number. But always an empty form displays...:-(

<?php

$connect=mysql_connect('localhost','root','');
mysql_select_db('bank',$connect);

if( isset($_POST['account_number']) && !empty($_POST['account_number']) ){
    
exit();

}
?>

<form method="post" action="modify_data.php">
  <div>Enter Account Number:
    <input type="text" name="account_number" value="" />
      <input type="submit" value="Submit"/>
  </div>
</form>

modify_data.php

<form name="form1" action="approve_data.php">
  <fieldset>
  <legend class="cap">Customer details</legend>
  <table width="75%" border="0" cellspacing="0" cellpadding="5" align="center">
  
  <?php
  
  //initilize variables
	            
                
                 $full_name = '';
                 $name_with_initials = '';
		 $phone_number = '';
                 $address = '';
                 $gender = '';
		 $date_of_birth = '';
		 $account_type = '';
		 $fd_period = '';
				 
	

	
$sql =sprintf("SELECT account_details. full_name,phone_number,address,gender,date_of_birth,account.name_with_initials,account_type,fd_period"." FROM account_details LEFT JOIN account"." ON account_details.`account_number`='%s'", mysql_real_escape_string($_POST['account_number']) );


$result=mysql_query($sql) or die( mysql_error() );

  if( mysql_num_rows($result)<1 )
  {
    echo "<p>No records found.</p>";
  }	
  
$query="select * from account LEFT JOIN account_details ON account.account_number = account_details.account_number";

$result = mysql_query($query) or die(mysql_error());
while ($row=mysql_fetch_array($result)){
                 
// replace blank variables with variables from the database	  
				
                $full_name = $row['full_name'];
                $name_with_initials = $row['name_with_initials'];
		$phone_number = $row['name_with_initials'];
                $address = $row['address'];
                $gender = $row['gender'];
		$date_of_birth = $row['date_of_birth'];
		$account_type = $row['account_type'];
		$fd_period = $row['fd_period'];
				
				
}
				
 
		   
	  ?>
                 <tr>
                  <td>&nbsp;</td>
                  <td class="title02">&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                 </tr>
                                          
                 <tr height="30">
                  <td width="10%">&nbsp;</td>


                 
                  
                        <td width="25%" class="title02" align="left">Full name</td>
                    <td width="55%" class="attribute1" align="left"><label>
              <input type="text" name="full_name" value="<?php echo $row['full_name']; ?>" class="attribute1" />
              </label></td>
                  <td width="10%">&nbsp;</td>
                 </tr>
                 <tr height="30">
                  <td>&nbsp;</td>
                  <td class="title02" align="left">Name with initials</td>
                  <td class="attribute1" align="left"><input type="text" name="name_with_initials" value="<?php echo $row['name_with_initials']; ?>                                                      " class="attribute1" /></td>
                 </tr>
                   <tr height="30">
                  <td width="10%">&nbsp;</td>


                  <td width="25%" class="title02" align="left">Phone Number</td>
                  <td width="55%" class="attribute1" align="left"><label>
                  <input type="text" name="phone_number" value="<?php echo $row['phone_number']; ?>" class="attribute1" />
                  </label></td>
                  <td width="10%">&nbsp;</td>
                 </tr>
                       <tr height="30">
                  <td width="10%">&nbsp;</td>


                  <td width="25%" class="title02" align="left">Address</td>
                  <td width="55%" class="attribute1" align="left"><label>
                    <textarea name="address" id="textarea" <?php echo $row['address']; ?> cols="45" rows="5"></textarea>
                  </label></td>
                  <td width="10%">&nbsp;</td> 
    <tr height="30">
                        
                  <td>&nbsp;</td>
                  <td class="title02" align="left">Gender</td>
                  <td class="attribute1" align="left"><label>
                    <select name="gender" id="select">
                           <option selected="selected"><?php echo $row['gender']; ?></option>
                      <option value="male">Male</option>
                            <option value="female">Female</option>
                  </select>
                  </label></td>
    <tr height="30">
                  <td>&nbsp;</td>
                  <td class="title02" align="left">Date of birth</td>
                  <td class="attribute1" align="left"><input type="Text" id="demo3" name="date_of_birth" value="<?php echo $row['date_of_birth'];                    ?>" maxlength="25" size="25"/><img src="../images/cal.gif" onClick= "javascript:NewCssCal('demo3','yyyyMMdd')" style="cursor:pointer"/>&nbsp;</td>
    </tr>
    <tr height="30">
        <td width="10%" height="41">&nbsp;</td>
        <td width="25%" class="title02" align="left">Account Type</td>
        <td width="65%" align="left" bgcolor="#FFFFFF" class="attribute1">
        <select name="account_type" onChange="fd_show(this.value)">
            <option selected="selected"><?php echo $row['account_type']; ?></option>
            <option value="savings_investment">Savings Investment</option>
            <option value="shakthi" >Shakthi</option>
            <option value="surathal">Surathal</option>
            <option value="abhimani_plus">Abhimani Plus</option>
            <option value="yasasa">Yasasa Certificates</option>
            <option value="fd">Fixed Deposits</option>
          </select>&nbsp;</td>
    <tr height="30">
      <td colspan="4">
          <div id="fd_box" style="visibility: hidden;">
          <table width="100%" border="0" cellspacing="0" cellpadding="5" align="center">
            <tr height="30"> </tr>
            <tr height="30">
              <td width="10%"></td>
              <td width="25%" class="title02" align="left">FD period</td>
              <td width="55%" class="attribute1" align="left"><select name="fd_period">
                  <option selected="selected"><?php echo $row['fd_period']; ?></option>
                  <option value="< 1">less than 1 year</option>
                  <option value="1-3 years" >1-3 years</option>
                  <option value="> 3">more than 3 years</option>
                  <option value="il">immediate loan</option>
              </select></td>
              <td width="10%"></td>
            </tr>
            <tr height="1"></tr>
<tr height="30"></tr>
          </table>    
         
      <tr height="30">
        <td>&nbsp;</td>
        <td width="25%" class="title02" align="left">&nbsp;</td>
        <td width="55%" align="left" bgcolor="#FFFFFF" class="attribute1">&nbsp;</td>
  </table>
  <p align="center">&nbsp;</p>
    <p align="center">
      <a href="approve_data.php">
       <label>
        <input type="submit" name="button2" id="button2" value="Modify" />
      </label></a>
      
      &nbsp;&nbsp;&nbsp;&nbsp;
    <label>
        <input type="submit" name="button2" id="button2" value="Help" />
      </label>
    </p>
  </fieldset>
  </td>
                 
                      
  </table>
    
</form>

This code should be on modify_data.php not in the first file, because there is no query to do:

$connect=mysql_connect('localhost','root','');
mysql_select_db('bank',$connect);

Changed. But still outputs an empty form..

if( isset($_POST) && !empty($_POST) ){

exit();

}

Seriously this code is of no use. Just delete it and use javascript.

Just Use Javascript Validation and submit its value to the modify_data.php , make a connection in modify_data.php file and retrieve value from previous page using post method . Build a select query on this this page using retrieved values and display data .

Hi

Can you please check your modify_data.php file

Are you getting the account_number text box value.

with help of GET function you can able to display the details

@ rv 1990; I removed that coding and check, but still the same.

I didn't get any text box values. After clicking on the submit button a form displays without any data. It means there is something wrong in my query in modify_data.php

Let me say one more thing. The data should be retrieved from two different tables. account_details and account.

account_number is the primary key of both the tables.

You want account number to be send to modify_data.php....
do one thing just add:
$acc_no = $_POST;
echo "$acc_no";
Try this . You will come to a conclusion about the account number confusion

The primary keys of both the tables are not going to impact more I think.

I got one more idea if you want to do validation in php then add this code in a new php page which acts as intermediate between the pages i.e. index page and modify_data.php

if( isset($_POST['account_number']) && !empty($_POST['account_number']) ){
echo "header(modify_data.php?account_number=$POST['account_number'])";
}
else
{
  // to the index page from where the form is submitted
}

This page will act as a validation purpose.

if( isset($_POST) && !empty($_POST) ){

exit();

}

Seriously this code is of no use. Just delete it and use javascript.

Just Use Javascript Validation and submit its value to the modify_data.php , make a connection in modify_data.php file and retrieve value from previous page using post method . Build a select query on this this page using retrieved values and display data .

This is TERRIBLE advice. Validation should never be done just on the client-side. All it takes is disabling javascript to be able to submit any data you want to the form. Or simply making a post/get request with something like curl.

Make it validate server-side (PHP) first, than worry about javascript validation as this benefits the user and prevents the need to submit the form for trivial issues.

First, have you tried turning error_reporting on? Error reporting is often disabled in environments. Just add error_reporting(E_ALL | E_STRICT); after your <?php tags in your files. This will ensure you are actually seeing EVERY php error even the notices.

Note: line numbers are relevant to your posted code.

Second, line 28 - 31 of modify_data.php If that query doesn't return any results, it will show your message but continue running your code after that. http://php.net/manual/en/function.exit.php - Just one way to terminate execution.

Third, the query on line 33 appears as though it will fetch all of the data in your db since there is no where condition to limit it.

Fourth, everything from line 51 onward is outside of your while loop. So it will never get populated with the values you are setting in your loop. http://php.net/manual/en/control-structures.while.php

Fifth, line 70, for example, this code: <?php echo $row['full_name']; ?> is using the database result that is set in the while loop instead of the local variable you have set its value too.

Sixth, line 95, <textarea name="address" id="textarea" <?php echo $row['address']; ?> cols="45" rows="5"></textarea> your variable is just plain in the wrong place. http://www.w3schools.com/tags/tag_textarea.asp

Seventh, your select outputs:

<select name="account_type" onChange="fd_show(this.value)">
            <option selected="selected"><?php echo $row['account_type']; ?></option>
            <option value="savings_investment">Savings Investment</option>
            <option value="shakthi" >Shakthi</option>
            <option value="surathal">Surathal</option>
            <option value="abhimani_plus">Abhimani Plus</option>
            <option value="yasasa">Yasasa Certificates</option>
            <option value="fd">Fixed Deposits</option>
          </select>&nbsp;</td>

That is not the way you set a select to a predetermined value. http://www.w3schools.com/tags/tag_option.asp

Eight, you have two submit buttons that are named exactly the same thing. Unless you are using javascript to control the action those buttons take they will do exactly the same thing regardless of their value (help vs modify), submit the form.

Lastly, you should NOT be using the mysql extension in php. Unless, you are using a very old version of php :icon_redface: or you are using a very old version of mysql :icon_redface:. By learning bad techniques now you will only hurt yourself further down the road. Read http://www.php.net/manual/en/mysqli.overview.php for some more information and look at the mysqli documentation for an "improved" extension.

@ mschroeder ; Thanks a lot for your detailed explanation. I have made changes to the modify_data.php coding.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<script src="datetimepicker_css.js">
</script>
<script LANGUAGE="JavaScript">
function fd_show(val){
if(val=="fd"){
   document.getElementById("fd_box").style.visibility = 'visible';
  }else{
   document.getElementById("fd_box").style.visibility = 'hidden';
  }
}
</script>

<script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>   

<form name="form1" action="">
  <fieldset>
  <legend class="cap">Customer details</legend>
  <table width="75%" border="0" cellspacing="0" cellpadding="5" align="center">
  
  <?php
  
   error_reporting(E_ALL | E_STRICT);
  
  $connect=mysql_connect('localhost','root','');
  mysql_select_db('bank',$connect);  
  
  $account_number='';


if(isset($_POST['account_number']))
    $account_number=$_POST['account_number'];
else
    $account_number='';
  
  //initilize variables
	            
                 $full_name = '';
                 $name_with_initials = '';
		 $phone_number = '';
                 $address = '';
                 $gender = '';
		 $date_of_birth = '';
		 $account_type = '';
		 $fd_period = '';


$sql =sprintf("SELECT account_details. full_name,phone_number,address,gender,date_of_birth,account.name_with_initials,account_type,fd_period"." FROM account_details LEFT JOIN account"." ON account_details.`account_number`='%s'", mysql_real_escape_string($_POST['account_number']) );


$result=mysql_query($sql) or die( mysql_error() );

  if( mysql_num_rows($result)==0 )
  {
    echo "<p>No records found.</p>";
    exit();	
  }	
  
              	   
$query ="SELECT account_details. full_name,phone_number,address,gender,date_of_birth,account.name_with_initials,account_type,fd_period"." FROM account_details LEFT JOIN account"." ON account_details.account_number=account.account_number";

$result = mysql_query($query) or die(mysql_error());
while ($row=mysql_fetch_array($result)){
                 
					   
	// replace blank variables with variables from the database	  
				
                $full_name = $row['full_name'];
                $name_with_initials = $row['name_with_initials'];
		$phone_number = $row['name_with_initials'];
                $address = $row['address'];
                $gender = $row['gender'];
		$date_of_birth = $row['date_of_birth'];
		$account_type = $row['account_type'];
		$fd_period = $row['fd_period'];
				
				

				
				
  
?>
		   
		   
	  
                 <tr>
                  <td>&nbsp;</td>
                  <td class="title02">&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                 </tr>
                                          
                 <tr height="30">
                  <td width="10%">&nbsp;</td>
                  
                  


                 
                  
                        <td width="25%" class="title02" align="left">Full name</td>
                    <td width="55%" class="attribute1" align="left"><label>
              <input type="text" name="full_name" value="<?php echo $row['full_name']; ?>" />
              </label></td>
                  <td width="10%">&nbsp;</td>
                 </tr>
                 <tr height="30">
                  <td>&nbsp;</td>
                  <td class="title02" align="left">Name with initials</td>
                  <td class="attribute1" align="left"><input type="text" name="name_with_initials" value="<?php echo $row['name_with_initials']; ?>                                                      " class="attribute1" /></td>
                 </tr>
                   <tr height="30">
                  <td width="10%">&nbsp;</td>


                  <td width="25%" class="title02" align="left">Phone Number</td>
                  <td width="55%" class="attribute1" align="left"><label>
                  <input type="text" name="phone_number" value="<?php echo $row['phone_number']; ?>" class="attribute1" />
                  </label></td>
                  <td width="10%">&nbsp;</td>
                 </tr>
                       <tr height="30">
                  <td width="10%">&nbsp;</td>


                  <td width="25%" class="title02" align="left">Address</td>
                  <td width="55%" class="attribute1" align="left"><label>
                    <textarea name="address" id="textarea" cols="45" rows="5"><?php echo $row['address']; ?></textarea>
                  </label></td>
                  <td width="10%">&nbsp;</td> 
    <tr height="30">
                        
                  <td>&nbsp;</td>
                  <td class="title02" align="left">Gender</td>
                  <td class="attribute1" align="left"><label>
                    <select name="gender" id="select">
                           <option selected="selected"><?php echo $row['gender']; ?></option>
                      <option value="male">Male</option>
                            <option value="female">Female</option>
                  </select>
                  </label></td>
    <tr height="30">
                  <td>&nbsp;</td>
                  <td class="title02" align="left">Date of birth</td>
                  <td class="attribute1" align="left"><input type="Text" id="demo3" name="date_of_birth" value="<?php echo $row['date_of_birth'];                    ?>" maxlength="25" size="25"/><img src="../images/cal.gif" onClick= "javascript:NewCssCal('demo3','yyyyMMdd')" style="cursor:pointer"/>&nbsp;</td>
    </tr>
    <tr height="30">
        <td width="10%" height="41">&nbsp;</td>
        <td width="25%" class="title02" align="left">Account Type</td>
        <td width="65%" align="left" bgcolor="#FFFFFF" class="attribute1">
        <select name="account_type" onChange="fd_show(this.value)">
            <option selected="selected"><?php echo $row['account_type']; ?></option>
            <option>Savings Investment</option>
            <option>Shakthi</option>
            <option>Surathal</option>
            <option>Abhimani Plus</option>
            <option>Yasasa Certificates</option>
            <option >Fixed Deposits</option>
          </select>&nbsp;</td>
    <tr height="30">
      <td colspan="4">
          <div id="fd_box" style="visibility: hidden;">
          <table width="100%" border="0" cellspacing="0" cellpadding="5" align="center">
            <tr height="30"> </tr>
            <tr height="30">
              <td width="10%"></td>
              <td width="25%" class="title02" align="left">FD period</td>
              <td width="55%" class="attribute1" align="left"><select name="fd_period">
                  <option selected="selected"><?php echo $row['fd_period']; ?></option>
                  <option>less than 1 year</option>
                  <option>1-3 years</option>
                  <option>more than 3 years</option>
                  <option>immediate loan</option>
              </select></td>
              <td width="10%"></td>
            </tr>
            <tr height="1"></tr>
<tr height="30"></tr>
          </table>    
         
      <tr height="30">
        <td>&nbsp;</td>
        <td width="25%" class="title02" align="left">&nbsp;</td>
        <td width="55%" align="left" bgcolor="#FFFFFF" class="attribute1">&nbsp;</td>
        
        <?php
		
		}
		?>
  </table>
  <p align="center">&nbsp;</p>
    <p align="center">
      <a href="approve_data.php">
       <label>
        <input type="submit" name="button1" id="button1" value="Modify" />
      </label></a>
      
      &nbsp;&nbsp;&nbsp;&nbsp;
    <label>
        <input type="submit" name="button2" id="button2" value="Help" />
      </label>
    </p>
  </fieldset>
  </td>
   


            
           
           
           
          
         </table>
    
</form>
</body>
</html>

When i enters the account number and click on submit button all the records were retrieved from the database. I think this is because of my query whic does not include "WHERE" clause. I have tried to include below coding.

$query="SELECT account_details.full_name,phone_number,address,gender,date_of_birth,account.name_with_initials,account_type,fd_period"."FROM account_details,account"."WHERE account_details.account_number=account.account_number";

This will generate following error.

Customer details You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.account_number=account.account_number' at line 1

Secondly, the echo "No records found" also not working.

Thirdly, If user selects the Account type as "fd". the fd_period dialog box never displays..

Looking for your quick response regarding above issues.

@ mschroeder I think you have not read the full thread. I have also mentioned the script which only uses validation through php not by javascript.

I did read the entire thread and took the time to read through the ops code and provide a detailed response. You may have provided some php assistance :icon_rolleyes: but you still made the statement as well as another poster that the op should drop php validation in favor of javascript. The problem with this, is that eventually someone else well come across this thread and read that post and think "this is a good idea, i should remove my server-side validation in lieu of javascript!" and then their application will be terribly vulnerable. The posts I quoted are TERRIBLE advice, and I stand by that.

Hi,

Itz ok..Can anyone help me out regarding my above problem?

The query issue is because you are not passing the submitted account id into your query. You do on line 57, but not on line 69. Can you explain why you have two separate queries here?

It is for the searching and selecting. I feel it is wrong. But i am bit confused. Could you help me? I think one query will do...

@ mschroeder ok dude I accept my fault. Lets make his doubt clear.The other post what I used for validation in php is also better ,I think . What is your opinion?

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.