Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1 <?
2 $link=mysql_connect("localhost","usuario","clave");
mysql_select_db("nombrebd",$link) OR DIE ("Error: No es posible
3
establecer la conexin");
4 ?>
Localhost: Indca a donde se conecta con la DB. Si la conexin es en el mismo
servidor, este es el valor que debe ir. Si la conexin se da en otro servidor, debemos
incluir la Ip del servidor. En este ltimo caso, el servidor deber tener las conexiones
remotas abiertas.
1 <?
2 include("conexion.php");
3 ?>
<head>
<title>Iniciar actualizacin.</title>
<META name='robot' content='noindex, nofollow'>
</head>
<body>
<div align="center">
<table border="0" width="600" style="font-family: Verdana; font-size:
8pt" id="table1">
<tr>
<td colspan="2"><h3 align="center">Actualizacin de datos</h3
></td>
</tr>
<form method="POST" action="form2.php">
<tr>
<td width="50%"> </td>
<td width="50%"> </td>
</tr>
<tr>
<td width="50%">
<p align="center"><b>ID del registro a actualizar: </b></td>
<td width="50%">
<p align="center"><input type="text" name="id" size="20"></td
>
</tr>
<tr>
<td width="50%"> </td>
<td width="50%"> </td>
</tr>
<tr>
<td width="100%" colspan="2">
<p align="center">
<input type="submit" value="Iniciar actualizacin" name="B1">
</td>
</tr>
</form>
</table>
</div>
</body>
</html>
======== form2.php
<html>
<head>
<title>Datos a actualizar.</title>
<META name='robot' content='noindex, nofollow'>
</head>
<?php
$id = $_POST['id'];
include('abre_conexion.php');
echo "
<body>
<div align='center'>
<table border='0' width='600' style='font-family: Verdana; font-size:
8pt' id='table1'>
<tr>
<td colspan='2'><h3 align='center'>Actualice los datos que co
nsidere</h3></td>
</tr>
<tr>
<td colspan='2'>En los campos del formulario puede ver los va
lores actuales,
si no se cambian los valores se mantienen iguales.</td>
</tr>
<form method='POST' action='actualiza.php'>
<tr>
<td width='50%'> </td>
<td width='50%'> </td>
</tr>
<tr>
<td width='50%'><p align='center'><b>Nombre: </b></td>
<td width='50%'><p align='center'><input type='text' name='no
mbre' size='20' value='".$registro['nombre']."'></td>
</tr>
<tr>
<td width='50%'><p align='center'><b>E-mail:</b></td>
<td width='50%'><p align='center'><input type='text' name='em
ail' size='20' value='".$registro['email']."'></td>
</tr>
<tr>
<td width='50%'> </td>
<td width='50%'> </td>
</tr>
<input type='hidden' name='id' value='$id'>
<tr>
<td width='100%' colspan='2'>
<p align='center'>
<input type='submit' value='Actualizar datos' name='B1'></td>
</tr>
</form>
</table>
</div>
";
}
include('cierra_conexion.php');
?>
</body>
</html>
======== actualiza.php
<html>
<head>
<title>Actualizacion completada.</title>
<META name='robot' content='noindex, nofollow'>
</head>
<body>
<?php
// Actualizamos en funcion del id que recibimos
$id = $_POST['id'];
$nombre = $_POST['nombre'];
$email = $_POST['email'];
$fecha = date("d-m-Y");
include('abre_conexion.php');
$sSQL="Update $tabla_db1 Set nombre='$nombre',email='$email',fecha='$fech
a' where id='$id'";
mysql_query($sSQL);
include('cierra_conexion.php');
echo "
<p>Los datos han sido actualizados con exito.</p>
<p><a href='javascript:history.go(-2)'>INICIO</a></p>
";
?>
</body>
</html>
<head>
<title>eliminar registros.</title>
<META name='robot' content='noindex, nofollow'>
</head>
<body>
<div align="center">
<table border="0" width="600" style="font-family: Verdana; font-size:
8pt" id="table1">
<tr>
<td colspan="2"><h3 align="center">Eliminacin de datos</h3><
/td>
</tr>
<form method="POST" action="borrar.php">
<tr>
<td width="50%"> </td>
<td width="50%"> </td>
</tr>
<tr>
<td width="50%">
<p align="center"><b>ID del registro a eliminar: </b></td>
<td width="50%">
<p align="center"><input type="text" name="id" size="20"></td
>
</tr>
<tr>
<td width="50%"> </td>
<td width="50%"> </td>
</tr>
<tr>
<td width="100%" colspan="2">
<p align="center">
<input type="submit" value="Eliminar" name="B1"></td>
</tr>
</form>
</table>
</div>
</body>
</html>
======== borrar.php
<html>
<head>
<title>Registro eliminado.</title>
<META name='robot' content='noindex, nofollow'>
</head>
<body>
<?php
// Actualizamos en funcion del id que recibimos
$id = $_POST['id'];
include('abre_conexion.php');
include('cierra_conexion.php');
echo "
<p>El registro ha sido eliminado con exito.</p>
</body>
</html>
Cul es la sintaxis para consultar datos en una base de datos MySql desde
Php?