Foros del Web » Programando para Internet » PHP »

Ayuda: Formulario PHP a MySQL

Estas en el tema de Ayuda: Formulario PHP a MySQL en el foro de PHP en Foros del Web. Hola a todos, espero que puedan ayudarme, soy principiante en PHP pero lo que quisiera hacer es un formulario que al clickear en enviar, aparte ...
  #1 (permalink)  
Antiguo 30/01/2008, 00:17
 
Fecha de Ingreso: enero-2008
Mensajes: 2
Antigüedad: 16 años, 2 meses
Puntos: 0
Ayuda: Formulario PHP a MySQL

Hola a todos, espero que puedan ayudarme, soy principiante en PHP pero lo que quisiera hacer es un formulario que al clickear en enviar, aparte de enviarme la información a mi email se ingrese en una base de datos en mi host. Este es el formulario pero no sé que hacer para que pueda accesar a la base de datos e ingresar los registros.

Código HTML:
<form enctype='multipart/form-data' action='process.php' method='post'>
<table width='50%' border=0>
<tr>
<td> Username <em>(debe ser el mismo con el que te registraste para que pueda ser v&aacute;lida tu petici&oacute;n)</em><font color='#ff0000'>*</font></td>
<td valign="top">
<input type=text name='Username' size=20></td>
</tr>
<tr>
<td> Nombre Completo<font color='#ff0000'>*</font></td>
<td>
<input type=text name='RealName' size=20></td></tr>
<tr>
<td> e-mail<font color='#ff0000'>*</font></td>
<td>
<input type=text name='email' size=20></td></tr>
<tr><td> Edad<font color='#ff0000'>*</font></td>
<td>
<input type=text name='Edad' size=5></td></tr>
<tr><td> Ciudad<font color='#ff0000'>*</font></td>
<td>
<input type=text name='Ciudad' size=20></td></tr>
<tr>
<td> Pa&iacute;s<font color='#ff0000'>*</font></td>
<td>
<input type=text name='País' size=20></td></tr>
<tr>
<td> G&eacute;nero<font color='#ff0000'>*</font></td>
<td>
<select name='Gender'><option value='Hombre'>Hombre<option value='Mujer'>Mujer</select></td></tr>
<tr>
<td> Tel&eacute;fono M&oacute;vil:</td>
<td>
<input type=text name='Telefono' size=20></td></tr>
<tr>
<td valign="top"> Direcci&oacute;n <em>(Calle, n&uacute;mero, colonia, municipio o poblaci&oacute;n, estado y c&oacute;digo postal):</em></td>
<td>
<textarea name='Adress' rows=5 cols=20></textarea></td></tr>
<tr>
<td> Crear cuenta de e-mail</td>
<td valign="top">
<input type=radio name='nuevoemail' value='Si'>
Si <input type=radio name='nuevoemail' value='No'>No</td>
</tr>
</table>
<input type='submit' value='Enviar Datos'>
 <input type=reset value='Borrar'>
</form> 
El archivo process.php es asi:

Código PHP:
<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','Username');
pt_register('POST','RealName');
pt_register('POST','email');
pt_register('POST','Edad');
pt_register('POST','Ciudad');
pt_register('POST','Country');
pt_register('POST','Gender');
pt_register('POST','Telefono');
pt_register('POST','Adress');
$Adress=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />"$Adress);pt_register('POST','nuevoemail');
if(
$Username=="" || $RealName=="" || $email=="" || $Edad=="" || $Ciudad=="" || $Country=="" || $Gender=="" ){
$errors=1;
$error.="<li>No haz rellenado uno o más de los campos requeridos. Por favor regresa e intenta de nuevo.";
}
if(
$errors==1) echo $error;
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Username: ".$Username."
RealName: "
.$RealName."
email: "
.$email."
Edad: "
.$Edad."
Ciudad: "
.$Ciudad."
Country: "
.$Country."
Gender: "
.$Gender."
Telefono: "
.$Telefono."
Adress: "
.$Adress."
nuevoemail: "
.$nuevoemail."
"
;
$message stripslashes($message);
mail("[email protected]","Form Submitted at your website",$message,"From: Formulario");

header("Refresh: 0;url=http://ejemplo.com");
?><?php 
}
?>
Y el global.inc.php asi:

Código PHP:
<?php

function pt_register()
{
  
$num_args func_num_args();
   
$vars = array();

   if (
$num_args >= 2) {
       
$method strtoupper(func_get_arg(0));

       if ((
$method != 'SESSION') && ($method != 'GET') && ($method != 'POST') && ($method != 'SERVER') && ($method != 'COOKIE') && ($method != 'ENV')) {
           die(
'The first argument of pt_register must be one of the following: GET, POST, SESSION, SERVER, COOKIE, or ENV');
     }

       
$varname "HTTP_{$method}_VARS";
      global ${
$varname};

       for (
$i 1$i $num_args$i++) {
           
$parameter func_get_arg($i);

           if (isset(${
$varname}[$parameter])) {
               global $
$parameter;
               $
$parameter = ${$varname}[$parameter];
          }

       }

   } else {
       die(
'You must specify at least two arguments');
   }

}

?>
Espero que puedan ayudarme, de antemano gracias
  #2 (permalink)  
Antiguo 30/01/2008, 07:21
Avatar de eulloa  
Fecha de Ingreso: octubre-2007
Ubicación: Donde caiga la noche, si mi hijo me deja
Mensajes: 691
Antigüedad: 16 años, 6 meses
Puntos: 5
Re: Ayuda: Formulario PHP a MySQL

Hola lex_0018, entiendo que no conoces las funciones de conección a BD de php ¿o sí?
Bueno por si acaso, mysql_connect,mysql_query("insert...) es lo que debes usar en el caso que ya tengas creada la Base de Datos, sino deberás crearla primero mediante otro mysq_query("create database...") y luego mysql_query("create table...");
Si te es factible creala directamente en mysql, luego haces las demás consultas desde tu código php.
salu2
  #3 (permalink)  
Antiguo 30/01/2008, 13:35
 
Fecha de Ingreso: enero-2008
Mensajes: 2
Antigüedad: 16 años, 2 meses
Puntos: 0
Re: Ayuda: Formulario PHP a MySQL

ok, investigué un poco del tema y encontré esto, ya he creado la base de datos y también la tabla.

Código PHP:
mysql_connect("$server","$user","$pass");  
mysql_select_db("$bd");  
mysql_query("insert into lockers (Username,RealName,email,Edad,Ciudad, Country,Gender,Telefono,Adress,nuevoemail) values ('$Username','$RealName','$email','$Edad','$Ciudad','$Country','$Gender','$Telefono','$Adress','$nuevoemail')"); 
donde en mysql_connect y mysql_select pondré los datos de acceso a mi db, cierto?
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:28.