Ver Mensaje Individual
  #3 (permalink)  
Antiguo 07/07/2010, 14:11
jahcoto
 
Fecha de Ingreso: julio-2010
Mensajes: 10
Antigüedad: 14 años, 8 meses
Puntos: 0
Respuesta: Problema con php y mysql

hola, gracias por responder a mi msj, tengo un archivo donde esta la funcion para conectarse el cual se llama conexion.php
<?php
function Conectarse()
{
if (!($link=mysql_connect("localhost","jahcoto","poll ito")))
{
echo "Error conectando a la base de datos.";
exit();
}
if (!mysql_select_db("prueba",$link))
{
echo "Error seleccionando la base de datos.";
exit();
}
return $link;
}
?><?php
function Conectarse()
{
if (!($link=mysql_connect("localhost","jahcoto","poll ito")))
{
echo "Error conectando a la base de datos.";
exit();
}
if (!mysql_select_db("prueba",$link))
{
echo "Error seleccionando la base de datos.";
exit();
}
return $link;
}
?>

y otro archivo donde hago la insercion de datos el cual se llama procesa.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
</head>

<body>
<?php
$nombre = $_POST['nombre'];
$apellidos = $_POST['apellidos'];
$loggin = $_POST['loggin'];
$pass = $_POST['password'];
include("conexion.php");
$link=Conectarse();
echo "Conexión con la base de datos conseguida.<br>";
mysql_query("insert into usuario (Nombre,Apellidos,Loggin,Contraseña) values ('$nombre','$apellidos','$loggin','$pass')",$link) ;
header("Location: registro.php");
mysql_close($link); //cierra la conexion

?>
</body>
</html>

y por ultimo recojo los datos de un form llamado registro.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>registro</title>
<link rel="stylesheet" type="text/css" href="./registro.css" media="all" />
<!--[if IE]>
<style type="text/css" media="all">.borderitem {border-style:solid;}</style>
<![endif]-->
</head>

<body>
<form action="procesa.php" method="post" enctype="multipart/form-data" name="registro" target="_self">
<div id="main">
<p class="Txt_Registrece">

Registrece

</p>
<br class="clearfloat" />
<p class="Txt_Nombre">

Nombre

</p>
<div id="Div">
<input name="nombre" type="text" size="26" maxlength="30" />
</div>
<div id="Div2">
<input name="apellidos" type="text" size="26" maxlength="45" />
</div>
<p class="Txt_Apellidos">

Apellidos

</p>
<br class="clearfloat" />
<p class="Txt_Loggin">

Loggin

</p>
<div id="Div3">
<input name="loggin" type="text" size="26" maxlength="15" />
</div>
<div id="Div4">
<input name="password" type="text" size="26" maxlength="10" />
</div>
<p class="Txt_Password">

Password

</p>
<br class="clearfloat" />
<div id="Div5">
<input name="guardar" type="submit" value="Guardar" />
</div>
<div id="Div6">
<input name="cancelar" type="button" value="Cancelar" />
</div>
<br class="clearfloat" />
</div>
</form>

</body>
</html>

Gracias de nuevo