?
Solved

How to fill a list/menu box using records in MySQL database?

Posted on 2008-10-22
3
Medium Priority
?
723 Views
Last Modified: 2013-12-13
Hi guys,

I'm developing a very short application for my intranet, on the form, I'm using "lastname", "secondlastname", "firstname" and "birthday" in this same order and below there's a list/menu box.

So, what I need, is that after a user enter the last name, I need to search on the data base for all records that match with lastname, then display them in the list/menu control.

Please help!

Thank you guys.

Here's my code:

<? 
session_start();
?>
<HTML>
<style type="text/css">
<!--
.style2 {font-size: 10px}
.style3 {
	color: #0000FF;
	font-weight: bold;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 18px;
}
.style6 {font-size: 18px; }
.style7 {font-family: Arial, Helvetica, sans-serif}
.style8 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 18px;
	color: #006600;
}
.style10 {font-size: xx-small; }
.style11 {font-family: Arial, Helvetica, sans-serif; font-size: 24px; }
.style13 {color: #0000FF}
-->
</style>
<BODY bgcolor="#E6E6E6">
<table width="91%" border="1" align="center">
  <tr>
    <td width="100%" bgcolor="#99FF33"><div align="center" class="style11">Registro de documentos </div></td>
  </tr>
</table>
<?
//----------------------------------------------------------
//Inicialización de variables.
$DBhost = "192.168.8.999";
$DBuser = "test";
$DBpass = "";
$DBName = "braceros";
$table = "registros";
?>
<div align="center">
  <p class="style10">&nbsp;</p>
  <table width="971" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="303"><div align="right"><span class="style3">Representaci&oacute;n:</span></div></td> 
      <td width="10">&nbsp;</td>
      <td width="658"> <div align="right" class="style8"></div>
      <div align="left" class="style8"><? echo "$sess_consulado"; ?></div></td>
    </tr>
  </table>
  <p>&nbsp;</p>
</div>
<form action="<? echo $PHP_SELF ?>" method="post" enctype="multipart/form-data" >
  <table width="663" border="1" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td width="213" height="30"><div align="right" class="style6"><font face="Arial, Helvetica, sans-serif">Apellido Paterno:</font></div></td>
      <td width="444" height="30"><span class="style6"><font face="Arial, Helvetica, sans-serif">
        <input name="paterno" type="text" id="paterno" size="60" maxlength="100">
        <input name="lista" type="submit" id="lista" value="Lista">
</font>    
    </span></tr>
    <tr>
      <td height="30"><div align="right" class="style6"><font face="Arial, Helvetica, sans-serif">Apellido Materno:</font></div></td>
      <td height="30"><span class="style6"><font face="Arial, Helvetica, sans-serif">
        <input name="materno" type="text" id="materno" size="60" maxlength="100">
      </font>     
    </span></tr>
    <tr>
      <td height="30"><div align="right" class="style6"><font face="Arial, Helvetica, sans-serif">Nombre:</font></div></td>
      <td height="30"><span class="style6"><font face="Arial, Helvetica, sans-serif">
        <input name="nombre" type="text" id="nombre" size="60" maxlength="100">
      </font>     
    </span></tr>
    <tr>
      <td height="30"><div align="right" class="style6"><font face="Arial, Helvetica, sans-serif">Fecha de Nacimiento:</font></div></td>
      <td height="30"><span class="style6"><font face="Arial, Helvetica, sans-serif">
        <input name="fechanac" type="text" id="fechanac" size="12" maxlength="10">
        <font face="Arial, Helvetica, sans-serif">        </font> <font face="Arial, Helvetica, sans-serif">
        
</font></font></span><span class="style13"><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif">(dd/mm/yyyy)</font></font></span>    
    </tr>
    <tr>
      <td height="30">&nbsp;</td>
      <td height="30"><input type="submit" name="Submit" value="Grabar">    
    </tr>
  </table>
</form>
 
<?
if (@$Submit) {
	$today = getdate (time());
	$day = $today[ "mday"];
	$month = $today["mon"];
	$year = $today["year"];
	$fecha = "$year-$month-$day";
	//---------------------------------------------------------------------------------------------------------
	$db = mysql_connect($DBhost,$DBuser,$DBpass) or die("No fué posible conectarse con la Base de Datos.");
	@mysql_select_db("$DBName",$db) or die("Unable to select database $DBName");
	$sql1 = "INSERT INTO $table (nombre,paterno,materno,fechanacimiento,fecharegistro,consulado) VALUES ('$nombre','$paterno','$materno','$fechanac','$fecha','$sess_consulado')";
	$result1 = mysql_query($sql1);
	//-------------------------------------------------------------------------------------
	//Este Código se ejecuta si se realizaron modificaciones a la DB
	echo('<div align="center"><h3>El Registro se Creó Exitosamente.</h3></div>');
}
?>
<table width="667" height="248" border="1" align="center">
  <tr>
    <td width="750"><form name="form1" method="post" action="">
      <select name="lista" size="12" id="lista" align="center">
        <option>------------------------------LISTA DE NOMBRES SIMILARES------------------------------</option>
      </select>
    </form></td>
  </tr>
</table>

Open in new window

0
Comment
Question by:lanmex
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
nick_bal earned 1200 total points
ID: 22782836

<form name="form1" method="post" action="thispage.php">
	<input type="hidden" name="action" value="1">
	Full Name: <input type="text" name="lastname" value="<? echo $_POST['fullname'];?>"> <br>
	<input type="submit" value="SEND">
</form>
<br><br><br>
 
<? 
if($_POST['action']==1){
 
	$sel = "select * from tablename where lastname='".$_POST['lastname']."'"; //replace the tablename and the element lastname
	$run = mysql_query($sel) or die(mysql_error());
	if(mysql_num_rows($run)>0){
	?>
	<table>
		<tr>
			<td>Lastname</td>
			<td>Second Lastname</td>
			<td>Firstname</td>
			<td>Birthday</td>
		</tr>
		<? while($row = mysql_fetch_assoc($run)){ //use while if there is chance to have more than one results?>
		<tr>
			<td><? echo $row['lastname'];?></td> <!-- Replace lastname with your element -->
			<td><? echo $row['secondlastname'];?></td> <!-- Replace secondlastname with your element -->
			<td><? echo $row['firstname'];?></td> <!-- Replace firstname with your element -->
			<td><? echo $row['birthday'];?></td> <!-- Replace birthday with your element -->
		</tr>	
		<? }?>
	</table>
	
	<? }else{?>
	No entries found
	<? }?>
<? }?>

Open in new window

0
 

Author Comment

by:lanmex
ID: 22787857
Thank you nick_bal

It works good!!!
0
 
LVL 1

Expert Comment

by:nick_bal
ID: 22789352
You are welcome :):):) Glad i helped :):):)
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question