Solved

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

Posted on 2008-10-22
3
688 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now