Comunidad de diseño web y desarrollo en internet online

no me muestra contenido de lista <select> al hacer update

Citar            
MensajeEscrito el 21 Feb 2014 06:35 pm
Hola, que tal?

tengo un pequenio problema con un select lista un file update.php

Al darle a editar en mi lista, voy al update.php, veo todo menos el contenido de mi lista y esto hace que al guardar me borre lo que estaba previamente seleccionado. No despliega la lista

Alguien puede ayudarme a ver el error?

se lo agradezco

Código PHP :




<?php

$host="localhost"; // Host name 
$username="rooot"; // Mysql username 
$password="admin"; // Mysql password 
$db_name="input_test"; // Database name 
$tbl_name="test_example"; // 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);

$modelo = $_POST['modelo']

?>




<table width="400" 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>&nbsp;</td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Lastname</strong></td>
<td align="center"><strong>Email</strong></td>
<td align="center"><strong>modelo</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="center">
<input name="name" type="text" id="name" value="<? echo $rows['name']; ?>">
</td>
<td align="center">
<input name="lastname" type="text" id="lastname" value="<? echo $rows['lastname']; ?>" size="15">
</td>
<td>
<input name="email" type="text" id="email" value="<? echo $rows['email']; ?>" size="15">
</td>
</tr>
<tr>
<td>&nbsp;</td>

<tr>
<td>

<select class ="modelo" name="modelo" selected="<?php print($modelo[0]['modelo']); ?>">
<select name="modelo" id= "modelo">
<option value="Sentra" <? if ($rows['modelo'] == "Sentra") echo "selected"; ?>>Sentra</option>
    <option value="Corolla" <? if ($rows['modelo'] == "Corolla") echo "selected"; ?>>Corolla</option>
    <option value="Yaris" <? if ($rows['modelo'] == "Yaris") echo "selected"; ?>>Yaris</option>
</select>
    
</td>
</tr>
<td>
<input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>">
</td>
<td>&nbsp;</td>

<td align="center">
<input type="submit" name="Submit" value="Submit">
</td>
<td>&nbsp;</td>
</tr>
</table>
</td>
</form>
</tr>
</table>

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

Por unasemana

Claber

166 de clabLevel



 

Venezuela

chrome
Citar            
MensajeEscrito el 21 Feb 2014 07:42 pm
lo resolvi asi

Código :



<?php

$host="localhost"; // Host name 
$username="rooot"; // Mysql username 
$password="admin"; // Mysql password 
$db_name="input_test"; // Database name 
$tbl_name="test_example"; // 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="400" 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>&nbsp;</td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Lastname</strong></td>
<td align="center"><strong>Email</strong></td>
<td align="center"><strong>modelo</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="center">
<input name="name" type="text" id="name" value="<? echo $rows['name']; ?>">
</td>
<td align="center">
<input name="lastname" type="text" id="lastname" value="<? echo $rows['lastname']; ?>" size="15">
</td>
<td>
<input name="email" type="text" id="email" value="<? echo $rows['email']; ?>" size="15">
</td>
</tr>
<tr>
<td>&nbsp;</td>

<tr>
<td>


<select name="modelo" id= "modelo">
<option value="Sentra" <?php if($rows['modelo']=='Sentra') echo "selected='selected'"; ?>>Sentra</option>
<option value="Corolla" <?php if($rows['modelo']=='Corolla') echo "selected='selected'"; ?>>Corolla</option>
<option value="Yaris" <?php if($rows['modelo']=='Yaris') echo "selected='selected'"; ?>>Yaris</option>
</select>
</select>
    
</td>
</tr>
<td>
<input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>">
</td>
<td>&nbsp;</td>

<td align="center">
<input type="submit" name="Submit" value="Submit">
</td>
<td>&nbsp;</td>
</tr>
</table>
</td>
</form>
</tr>
</table>

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

Por unasemana

Claber

166 de clabLevel



 

Venezuela

chrome

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.