Solved

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

Posted on 2008-10-22
3
710 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
nick_bal earned 400 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

690 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