Cita:
Iniciado por memoadian primero separa el html del php
no pongas tanto html entre comillas:
luego usa una condicional:
Código PHP:
Ver original<?php
if($enabled == 1){
$checked == 'checked="checked"';
}else{
$checked = '';
}
?>
<tr><td style="background-color: #D2232A; color: white;">Piloto activo?</td><td><input type="checkbox" name="activo" <?php echo $checked ?> /></td></tr>"
Lo he añadido así pero no funciona:
Código PHP:
$id = $_GET["id"];
include('db.inc.php');
$connection = mysql_connect($DBHost, $DBUser, $DBPass);
if (!$connection){
die ("No se puede conectar con la base de datos: <br />". mysql_error());
}
$db_select = mysql_select_db($DBName);
if (!$db_select){
die ("No se puede seleccionar la base de datos: <br />". mysql_error());
}
$query = "SELECT * FROM Pilots WHERE ID = $id";
$result = mysql_query( $query );
if (!$result)
{
die ("No se puede hacer la consulta en la base de datos: <br />". mysql_error());
}
?>
<form method="post" action="editar-piloto.php">
<?
echo '<table border="0">';
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
echo "<tr><td style=\"background-color: #D2232A; color: white;\">ID</td><td><input type=\"text\" name=\"id\" size=\"3\" value=\"";
echo $row["ID"] . '"></td></tr>';
echo "<tr><td style=\"background-color: #D2232A; color: white;\">Licencia</td><td><input type=\"text\" name=\"licencia\" size=\"7\" value=\"";
echo $row["Licencia"] . '"></td></tr>';
echo "<tr><td style=\"background-color: #D2232A; color: white;\">Nombre</td><td><input type=\"text\" name=\"nombre\" size=\"35\" value=\"";
echo $row["Name"] . '"></td></tr>';
echo "<tr><td style=\"background-color: #D2232A; color: white;\">Email</td><td><input type=\"text\" name=\"email\" size=\"30\" value=\"";
echo $row["Email"] . '"></td></tr>';
echo "<tr><td style=\"background-color: #D2232A; color: white;\">Contraseña</td><td><input type=\"password\" name=\"pass\" size=\"3\" value=\"";
echo $row["Pass"] . '"></td></tr>';
echo "<tr><td style=\"background-color: #D2232A; color: white;\">País</td><td><input type=\"text\" name=\"pais\" size=\"10\" value=\"";
echo $row["Pais"] . '"></td></tr>';
echo "<tr><td style=\"background-color: #D2232A; color: white;\">VID IVAO</td><td><input type=\"text\" name=\"vid_ivao\" size=\"10\" value=\"";
echo $row["VID_IVAO"] . '"</td></tr>';
echo "<tr><td style=\"background-color: #D2232A; color: white;\">ID VATSIM</td><td><input type=\"text\" name=\"id_vatsim\" size=\"10\" value=\"";
echo $row["ID_VATSIM"] . '"></td></tr>';
echo "<tr><td style=\"background-color: #D2232A; color: white;\">Localización</td><td><input type=\"text\" name=\"loc\" size=\"4\" value=\"";
echo $row["LOC"] . '"></td></tr>';
$res = mysql_query("SELECT * FROM Pilots WHERE ID = '$id'") or die('No se ha podido encontrar la distancia');
$enabled = mysql_result($res, 0, 'Enabled');
$alumno = mysql_result($res, 0, 'HabM');
if($enabled == 1){
$checked == 'checked=\"checked\"';
}else{
$checked = '';
}
echo $checked;
echo "<tr><td style=\"background-color: #D2232A; color: white;\">Piloto activo?</td><td><input type=\"checkbox\" name=\"activo\" <?php echo $checked ?> /></td></tr>";
if($alumno == 1){
$checked == 'checked=\"checked\"';
}else{
$checked = '';
}
echo "<tr><td style=\"background-color: #D2232A; color: white;\">Alumno</td><td><input type=\"checkbox\" name=\"alumno\" <?php echo $checked; /></td></tr>";
echo "<tr><td><input type=\"submit\" value=\"Editar Piloto\" name=\"enviar\"></td></tr> ";
}
echo "</table>";
?>
</form>
<?
}
mysql_close();
?>
</body>
</html>