Please help me to write a PHP code for following .

i have name , address , loanno (unique) , fup as fields in my database loandata.

i want a screen in which i enter a loan number and it should search the loan no. in lonono and if data matches it should print name,address,fup of that loanno

I am a beginner in PHP . please help!!!

commented: We help people solve their problems, we don;t just don't write codes for plople here. +0

	$host_name = "localhost";
	$user_name = "root";
	$password = "rootwdp";
	$db_name = "db_test";
	$con = mysql_connect($host_name,$user_name,$password);
	$db_select = mysql_select_db($db_name,$con);
		$qry = "SELECT `name`, `address`, `fup` FROM `table_name` WHERE `loanno` = '".$_POST['selLoan']."'";
		$res = mysql_fetch_array(mysql_query($qry));
	$rows = mysql_query("SELECT `loanno` FROM `table_name`");
<form method="post">
    <select name="selLoan" onChange="javascript:this.form.submit();">
        <option value="">Select Loan no</option>
        <?php while($row = mysql_fetch_array($rows)){ ?>
        <option value="<?php echo $row['loanno']; ?>" <?php if($_POST['selLoan'] == $row['loanno']) {?> selected="selected" <?php } ?>><?php echo $row['loanno']; ?></option>
    <?php } ?>

<?php if(@mysql_num_rows(mysql_query($qry))){ ?>
<table border="0">
    	<td>Name : </td>	<td><?php echo $res['name']; ?></td>
        <td>Address : </td>	<td><?php echo $res['address']; ?></td>
        <td>FUP : </td>		<td><?php echo $res['fup']; ?></td>
<?php } ?>

You just have to change the
table_name in each query
Ii may help you.

You could do this with a simple search box, drop menu (in case you want to search by things other than just loan number) and then a select query. Finally echo everything.

This is all pretty beginner stuff. I found a tutorial here (

I made a few small changes. The pagination to $PHP_SELF doesnt work properly, maybe someone else here could tell you why.

You need to make changes to code line 32, 35, & 39.

<form name="form" action="search_sample.php" method="get">
  <input type="text" name="q" />
  <input type="submit" name="Submit" value="Search" />
Now, enter the following PHP. Follow the PHP comments for what the script is doing, if you get stuck, tell us in the forums!


  // Get the search variable from URL

  $var = @$_GET['q'] ;
  $trimmed = trim($var); //trim whitespace from the stored variable

// rows to return

// check for an empty string and display a message.
if ($trimmed == "")
  echo "<p>Please enter a search...</p>";

// check for a search parameter
if (!isset($var))
  echo "<p>We dont seem to have a search parameter!</p>";

//connect to your database ** EDIT REQUIRED HERE **
mysql_connect("localhost","username","password"); //(host, username, password)

//specify database ** EDIT REQUIRED HERE **
mysql_select_db("databasename") or die("Unable to select database"); //select which database we're using

$field = 'firstname';
// Build SQL Query  
$query = "select * from tablename where $field like \"%$trimmed%\"  
  order by $field"; // EDIT HERE and specify your table and field names for the SQL query


// If we have no results, offer a google search as an alternative

if ($numrows == 0)
  echo "<h4>Results</h4>";
  echo "<p>Sorry, your search: &quot;" . $trimmed . "&quot; returned zero results</p>";

// google
 echo "<p><a href=\"" 
  . $trimmed . "\" target=\"_blank\" title=\"Look up 
  " . $trimmed . " on Google\">Click here</a> to try the 
  search on google</p>";

// next determine if s has been passed to script, if not use 0
  if (empty($s)) {

// get results
  $query .= " limit $s,$limit";
  $result = mysql_query($query) or die("Couldn't execute query");

// display what the person searched for
echo "<p>You searched for: &quot;" . $var . "&quot;</p>";

// begin to show results set
echo "<h3>Results</h3>";
$count = 1 + $s ;

// now you can display the results returned
  while ($row= mysql_fetch_array($result)) {
  $title = $row["$field"];

  echo "$count.) &nbsp;$title <br>" ;
  $count++ ;

$currPage = (($s/$limit) + 1);

//break before paging
  echo "<br />";

  // next we need to do the links to other results
  if ($s>=1) { // bypass PREV link if s is 0
  print "&nbsp;<a href=\"$PHP_SELF?s=$prevs&q=$var\">&lt;&lt; 
  Prev 10</a>&nbsp&nbsp;";

// calculate number of pages needing links

// $pages now contains int of pages needed unless there is a remainder from division

  if ($numrows%$limit) {
  // has remainder so add one page

// check to see if last page
  if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {

  // not last page so give NEXT link

  echo "&nbsp;<a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 &gt;&gt;</a>";

$a = $s + ($limit) ;
  if ($a > $numrows) { $a = $numrows ; }
  $b = $s + 1 ;
  echo "<p>Showing results $b to $a of $numrows</p>";

We don't solve people's problem for them here, we only help people solve their own problems. To help you do what you are trying to do, you must start something yourself so we can guide/help you where possible. Anyway, I will help you. If you are learning PHP, this means that you probably have some knowledge of HTMl, databases(MySQL), and some basics of the PHP scripting language. Simply combine the little you know of these languages and you are done, and don't hesitate to let us know if you encounter any problem.

commented: dude if u know it doesnt mean all people can get by knowing these coding ok? dont be selfish if u dont wanna help go and be busy helping other people in ur category +0
commented: Exactly +3