Jump to content

remember Selected item of a list on update file


unasemana

Recommended Posts

hi, i have this update.php  file that read my clients db. everything is fine but, i cant make it to remember the list of the form, so it gets the first one again, not a selected one.

 

im triying something like this but its not working : any ideas? thanks for your time.

<select name="modelo" id= "modelo">
<option value = "Sentra" <?php compare($row->role, 'sentra'); ?>>Sentra</option>
<option value = "Corolla" <?php compare ($row->role, 'corolla'); ?>>Corolla</option>
<option value = "Chavez" <?php compare($row->role, 'chavez'); ?>>Chavez</option>
</select>

update.php (full)


<?php
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password="root"; // Mysql password 
$db_name="rmm_invoice"; // Database name 
$tbl_name="clientes"; // Table name  

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// get value of id that sent from address bar
$id=$_GET['id'];

// Retrieve data from database 
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);


?>

<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="update_ac.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td> </td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>Nombre</strong></td>
<td align="center"><strong>Apellido</strong></td>
<td align="center"><strong>Email</strong></td>
<td align="center"><strong>Telf_hab</strong></td>
<td align="center"><strong>Telf_cel</strong></td>
<td align="center"><strong>Direccion</strong></td>
<td align="center"><strong>Modelo</strong></td>

</tr>
<tr>
<td> </td>
<td align="center">
<? echo $rows['id']; ?>
</td>
<td align="center">
<input name="nombre" type="text" id="nombre" value="<? echo $rows['nombre']; ?>">
</td>
<td align="center">
<input name="apellido" type="text" id="apellido" value="<? echo $rows['apellido']; ?>" size="15">
</td>
<td>
<input name="email" type="text" id="email" value="<? echo $rows['email']; ?>" size="15">
</td>
<td align="center">
<input name="telf_hab" type="text" id="telf_hab" value="<? echo $rows['telf_hab']; ?>">
</td>
<td align="center">
<input name="telf_cel" type="text" id="telf_cel" value="<? echo $rows['telf_cel']; ?>" size="15">
</td>
<td>
<input name="direccion" type="text" id="direccion" value="<? echo $rows['direccion']; ?>" size="15">
</td>
</tr>
<tr>
<select name="modelo" id= "modelo">
<option value = "Sentra" <?php compare($row->role, 'sentra'); ?>>Sentra</option>
<option value = "Corolla" <?php compare ($row->role, 'corolla'); ?>>Corolla</option>
<option value = "Chavez" <?php compare($row->role, 'chavez'); ?>>Chavez</option>
</select>



</tr>
<tr>
<td> </td>
<td>
<input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>">
</td>
<td align="center">
<input type="submit" name="Submit" value="Guardar">
</td>
<td> </td>
</tr>
</table>
</td>
</form>
</tr>
</table>

<?php
// close connection 
mysql_close();
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.