elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  PHP (Moderador: #!drvy)
| | | |-+  PHP y SQL Problemas para hacer un peque~o formulario
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] 2 Ir Abajo Respuesta Imprimir
Autor Tema: PHP y SQL Problemas para hacer un peque~o formulario  (Leído 4,833 veces)
pritguy

Desconectado Desconectado

Mensajes: 9


Ver Perfil
PHP y SQL Problemas para hacer un peque~o formulario
« en: 5 Mayo 2009, 07:56 am »

 estoy tratando se hacer un peque~O formulario  que se deposite la data en mi hosting   y no me sale alguien me puede ayudar?

<?php
$bd=mysql_connect("localhost","jerbix_base","aon") or die ("No puedo connectarme a base de datos");
mysql_select_db("jerbix_base");

$opt=$HTTP_GET_VARS["OPT"];

if ($opt==1)

{
   $nombre=$HTTP_GET_VARS["nombre"];
   $email=$HTTP_GET_VARS["email"];
   
   $sql="insert into id_jerbix_base (nombre, email) values ('".$nombre."','".$email."');
   $res=mysql_query($sql,$bd) or die (mysql_error());
   
?>

<html>

<title>formulario</title>

<script language="javascript">

function verifica()
{
  if (f.email.value=="")
  {
   alert ("por favor ingrese su email");
    return;
  }
  f.opt.value=1
  f.submit();
}

</script>
<body>

<form name="f">
<input type="hidden" name="opt">
<table width="200" border="0">
  <tr>
    <td width="63">Nombre</td>
    <td width="121"><form name="nombre" method="post" action="">
      <label>
        <input type="text" name="nombre" id="nombre" />
      </label>
    </form></td>
  </tr>
  <tr>
    <td>Email</td>
    <td><form name="email" method="post" action="">
      <label>
        <input type="text" name="email" id="email" />
      </label>
    </form></td>
  </tr>
</table>
<table width="200" border="0">
  <tr>
    <td><form name="form3" method="post" action="">
      <label>
        <input type="submit" name="submit" value="Submit" onclick=verifica() /> />
      </label>
    </form></td>
  </tr>
</table>
</form>
</body>
</html>


« Última modificación: 5 Mayo 2009, 07:58 am por pritguy » En línea

luiggy2


Desconectado Desconectado

Mensajes: 439


¡ Hello word ! XD


Ver Perfil
Re: PHP y SQL Problemas para hacer un peque~o formulario
« Respuesta #1 en: 5 Mayo 2009, 15:58 pm »

Código
  1.  
  2. <?php
  3. $bd=mysql_connect("localhost","jerbix_base","aon") or die ("No puedo connectarme a base de datos");
  4. mysql_select_db("jerbix_base");
  5.  
  6. $opt=$HTTP_GET_VARS["OPT"];
  7.  
  8. if ($opt==1)
  9.  
  10. {
  11.   $nombre=$HTTP_GET_VARS["nombre"];
  12.   $email=$HTTP_GET_VARS["email"];
  13.  
  14.   $sql="insert into id_jerbix_base (nombre, email) values ('".$nombre."','".$email."')"; // FALTABAN estas comillas
  15.   $res=mysql_query($sql) or die (mysql_error());
  16.  
  17. ?>
  18.  
  19. <html>
  20.  
  21. <title>formulario</title>
  22.  
  23. <script language="javascript">
  24.  
  25. function verifica()
  26. {
  27.  if (f.email.value=="")
  28.  {
  29.   alert ("por favor ingrese su email");
  30.    return;
  31.  }
  32.  f.opt.value=1
  33.  f.submit();
  34. }
  35.  
  36. </script>
  37. <body>
  38.  
  39. <form name="f">
  40. <input type="hidden" name="opt">
  41. <table width="200" border="0">
  42.  <tr>
  43.    <td width="63">Nombre</td>
  44.    <td width="121"><form name="nombre" method="post" action="">
  45.      <label>
  46.        <input type="text" name="nombre" id="nombre" />
  47.      </label>
  48.    </form></td>
  49.  </tr>
  50.  <tr>
  51.    <td>Email</td>
  52.    <td><form name="email" method="post" action="">
  53.      <label>
  54.        <input type="text" name="email" id="email" />
  55.      </label>
  56.    </form></td>
  57.  </tr>
  58. </table>
  59. <table width="200" border="0">
  60.  <tr>
  61.    <td><form name="form3" method="post" action="">
  62.      <label>
  63.        <input type="submit" name="submit" value="Submit" onclick=verifica() /> />
  64.      </label>
  65.    </form></td>
  66.  </tr>
  67. </table>
  68. </form>
  69. </body>
  70. </html>

No crees que así se lee mejor ???

respecto a tu pregunta:

Te faltan unas comillas al principio (está en el código corregidas).
Yo te recomendaría que cerraras la conexión al acabar mysql_close()

A tu html le sobra un /> aquí:   <input type="submit" name="submit" value="Submit" onclick=verifica() /> />

El resto no te puedo decir, ya que javascript no se.

También he cambiado algo más por ahí.



Saludos!


« Última modificación: 5 Mayo 2009, 16:01 pm por luiggy2 » En línea

" Las grandes ideas suelen salir la mayoría de veces de grandes estupideces "
#!drvy
Moderador
***
Desconectado Desconectado

Mensajes: 5.850



Ver Perfil WWW
Re: PHP y SQL Problemas para hacer un peque~o formulario
« Respuesta #2 en: 5 Mayo 2009, 16:42 pm »

Tu codigo es un desastre total   :-\

Código
  1. <?php
  2. $bd=mysql_connect("localhost","usuario","password") or die ("No puedo connectarme a base de datos");
  3. mysql_select_db("jerbix_base");
  4.  
  5.  
  6. if (isset($_POST['opt']))
  7.  
  8. {
  9.   $nombre=mysql_real_escape_string($_POST['nombre']);
  10.   $email=mysql_real_escape_string($_POST['email']);
  11.  
  12.    mysql_query("INSERT INTO id_jerbix_base (nombre, email) VALUES ('".$nombre."', '".$email."')") or die (mysql_error());
  13. }
  14.  
  15. ?>
  16.  
  17. <html>
  18.  
  19. <title>Forumario</title>
  20.  
  21. <script language="javascript">
  22.  
  23. function verifica()
  24. {
  25.  if (f.email.value=="")
  26.  {
  27.   alert ("por favor ingrese su email");
  28.    return;
  29.  }
  30.  f.opt.value=1
  31.  f.submit();
  32. }
  33.  
  34. </script>
  35. <body>
  36.  
  37. <form name="f" action="" method="post">
  38. <table width="200" border="0">
  39.  <tr><td width="63">Nombre: <br><input type="text" name="nombre"><input type="hidden" name="opt" /></td></tr>
  40.  <tr><td width="63">E-mail: <br><input type="text" name="email" /></td></tr>
  41.  <tr><td width="63"><input type="button" value="Enviar" onclick="verifica()" /></td></tr>
  42. </table>
  43. </form>
  44.  
  45.  
  46. </body>
  47. </html>

· Utilizamos isset para comprobar si la variable opt esta definida...de este modo te ahorras el error de que no es definida...
· Utilizamos $_POST en caso de envio por post y $_GET en caso de envio por url..
· SIEMPRE PERO QUE SIEMPRE LIMPIAMOS LAS VARIABLES ANTES DE UTILIZARLAS PARA BASE DE DATOS O IMPRIMIRLAS EN LA PAGINA
· Siempre cerramos el IF con } antes de cerrar PHP porque sino salta error

No te hacen falta tantos forms...con uno te basta...


Saludos
« Última modificación: 5 Mayo 2009, 16:46 pm por BadStupidMonkey » En línea

pritguy

Desconectado Desconectado

Mensajes: 9


Ver Perfil
Re: PHP y SQL Problemas para hacer un peque~o formulario
« Respuesta #3 en: 5 Mayo 2009, 17:48 pm »

Gracias BadStupidMonkey y luiggy2 por la ayuda.

ahora  tengo  otro problemita jajaa . Cuando entro para probarlo no se connecta al MySQL . Verifique  username  y Pass  que podria ser ademas?

EL  codigo lo tengo exactamente como me lo envio Badstupidmonkey .

Citar
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/content/j/e/r/jerbix/html/index3.php on line 3
En línea

#!drvy
Moderador
***
Desconectado Desconectado

Mensajes: 5.850



Ver Perfil WWW
Re: PHP y SQL Problemas para hacer un peque~o formulario
« Respuesta #4 en: 5 Mayo 2009, 19:28 pm »

Probablemente el servidor mysql no este en servidor local o no este instalado... si es un hosting (osea no lo estas testeando en tu propia pc) lo mas probable es que tengas que cambiar localhost por el servidor que te dan en el hosting. Otra cosa es que dicho hosting no tenga soporte para mysql  :¬¬




Saludos
En línea

pritguy

Desconectado Desconectado

Mensajes: 9


Ver Perfil
Re: PHP y SQL Problemas para hacer un peque~o formulario
« Respuesta #5 en: 5 Mayo 2009, 23:31 pm »

GRACIAS se me paso esa lol . Ya me salio!!! Gracias!
En línea

pritguy

Desconectado Desconectado

Mensajes: 9


Ver Perfil
Re: PHP y SQL Problemas para hacer un peque~o formulario
« Respuesta #6 en: 6 Mayo 2009, 05:39 am »

Solo  el email  y el nombre son los que llegan a mi base de datos que podria ser?  el problema mio es el formulario  solo llega a mi base de datos el campo de email y de nombre. GRACIAS

Código
  1. <?php
  2. $bd=mysql_connect("host","jmyname","my pass") or die ("No puedo connectarme a base de datos");
  3. mysql_select_db("database");
  4.  
  5.  
  6. if (isset($_POST['opt']))
  7.  
  8. {
  9.   $nombre=mysql_real_escape_string($_POST['nombre']);
  10.   $email=mysql_real_escape_string($_POST['email']);
  11.   $email=mysql_real_escape_string($_POST['telefono']);
  12.   $email=mysql_real_escape_string($_POST['direccion']);
  13.   $email=mysql_real_escape_string($_POST['asunto']);
  14.  
  15.    mysql_query("INSERT INTO jerbix_lead (nombre, email, telefono, direccion, asunto) VALUES ('".$nombre."', '".$email."', '".$telefono."','".$direccion."','".$asunto."')") or die (mysql_error());
  16. }
  17.  
  18. ?>
  19. <head>
  20. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  21. <title>Untitled Document</title>
  22. <style type="text/css">
  23. <!--
  24. body  {
  25. font: 100% Verdana, Arial, Helvetica, sans-serif;
  26. background: #666666;
  27. margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
  28. padding: 0;
  29. text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
  30. color: #000000;
  31. }
  32. .twoColFixLtHdr #container {
  33. width: 780px;  /* using 20px less than a full 800px width allows for browser chrome and avoids a horizontal scroll bar */
  34. background: #FFFFFF;
  35. margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
  36. border: 1px solid #000000;
  37. text-align: left; /* this overrides the text-align: center on the body element. */
  38. }
  39. .twoColFixLtHdr #header {
  40. background: #DDDDDD;
  41. padding: 0 10px 0 20px;  /* this padding matches the left alignment of the elements in the divs that appear beneath it. If an image is used in the #header instead of text, you may want to remove the padding. */
  42. }
  43. .twoColFixLtHdr #header h1 {
  44. margin: 0; /* zeroing the margin of the last element in the #header div will avoid margin collapse - an unexplainable space between divs. If the div has a border around it, this is not necessary as that also avoids the margin collapse */
  45. padding: 10px 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */
  46. }
  47. .twoColFixLtHdr #sidebar1 {
  48. float: left; /* since this element is floated, a width must be given */
  49. width: 200px; /* the actual width of this div, in standards-compliant browsers, or standards mode in Internet Explorer will include the padding and border in addition to the width */
  50. background: #EBEBEB; /* the background color will be displayed for the length of the content in the column, but no further */
  51. padding: 15px 10px 15px 20px;
  52. }
  53. .twoColFixLtHdr #mainContent {
  54. margin: 0 0 0 250px; /* the left margin on this div element creates the column down the left side of the page - no matter how much content the sidebar1 div contains, the column space will remain. You can remove this margin if you want the #mainContent div's text to fill the #sidebar1 space when the content in #sidebar1 ends. */
  55. padding: 0 20px; /* remember that padding is the space inside the div box and margin is the space outside the div box */
  56. text-align: left;
  57. }
  58. .twoColFixLtHdr #footer {
  59. padding: 0 10px 0 20px; /* this padding matches the left alignment of the elements in the divs that appear above it. */
  60. background:#DDDDDD;
  61. }
  62. .twoColFixLtHdr #footer p {
  63. margin: 0; /* zeroing the margins of the first element in the footer will avoid the possibility of margin collapse - a space between divs */
  64. padding: 10px 0; /* padding on this element will create space, just as the the margin would have, without the margin collapse issue */
  65. }
  66. .fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
  67. float: right;
  68. margin-left: 8px;
  69. }
  70. .fltlft { /* this class can be used to float an element left in your page */
  71. float: left;
  72. margin-right: 8px;
  73. }
  74. .clearfloat { /* this class should be placed on a div or break element and should be the final element before the close of a container that should fully contain a float */
  75. clear:both;
  76.    height:0;
  77.    font-size: 1px;
  78.    line-height: 0px;
  79. }
  80. -->
  81. </style><!--[if IE 5]>
  82. <style type="text/css">
  83. /* place css box model fixes for IE 5* in this conditional comment */
  84. .twoColFixLtHdr #sidebar1 { width: 230px; }
  85. </style>
  86. <![endif]--><!--[if IE]>
  87. <style type="text/css">
  88. /* place css fixes for all versions of IE in this conditional comment */
  89. .twoColFixLtHdr #sidebar1 { padding-top: 30px; }
  90. .twoColFixLtHdr #mainContent { zoom: 1; }
  91. /* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
  92. </style>
  93. <![endif]--></head>
  94.  
  95. <body class="twoColFixLtHdr">
  96.  
  97. <div id="container">
  98.  <div id="header">
  99.    <h1>Reparamos Desktops y Laptops</h1>
  100.  <!-- end #header --></div>
  101.  <div id="sidebar1">
  102.    <!-- end #sidebar1 -->
  103.  </div>
  104.  <div id="mainContent">
  105.    <h1>Solicitud de Servicios</h1>
  106.    <script language="javascript">
  107.  
  108. function verifica()
  109. {
  110.  if (f.email.value=="")
  111.  {
  112.   alert ("por favor ingrese su email");
  113.    return;
  114.  }
  115.  f.opt.value=1
  116.  f.submit();
  117. }
  118.  
  119. </script>
  120.  
  121.    <form name="f" action="" method="post">
  122.    <table width="200" border="0">
  123.      <caption>
  124.      Formulario
  125.      </caption>
  126.      <tr>
  127.        <tr><td width="63">Nombre: <br><input type="text" name="nombre"><input type="hidden" name="opt" /></td></tr>
  128.  <tr><td width="63">Phone Number: <br><input type="text" name="telefono"><input type="hidden" name="opt"/></td></tr>
  129.  <tr><td width="63">Direccion: <br><input type="text" name="dirrecion"><input type="hidden" name="opt" /></td></tr>
  130.  <tr><td width="63">E-mail: <br><input type="text" name="email"><input type="hidden" name="opt"/></td></tr>
  131.  <tr><td width="63">Asunto <br><textarea name="asunto" rows="4"></textarea> <input type="hidden" name="opt" /></td></tr><tr><td width="63"><input type="button" value="Enviar" onClick="verifica()" /></td></tr></tr>
  132.      </table>
  133.      </form>
  134.  
  135.  
  136.  
  137. <!-- end #mainContent --></div>
  138. <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
  139.  <div id="footer">
  140.    <p>Footer</p>
  141.  <!-- end #footer --></div>
  142. <!-- end #container --></div>
  143. </body>
  144. </html>
En línea

#!drvy
Moderador
***
Desconectado Desconectado

Mensajes: 5.850



Ver Perfil WWW
Re: PHP y SQL Problemas para hacer un peque~o formulario
« Respuesta #7 en: 6 Mayo 2009, 09:53 am »

No cambiaste el nombre de las variables al principio aqui:

Código
  1.  
  2.   $nombre=mysql_real_escape_string($_POST['nombre']);
  3.   $email=mysql_real_escape_string($_POST['email']);
  4.   $email=mysql_real_escape_string($_POST['telefono']);
  5.   $email=mysql_real_escape_string($_POST['direccion']);
  6.   $email=mysql_real_escape_string($_POST['asunto']);
  7.  

Ademas si te fijas aqui:
Código
  1. $email=mysql_real_escape_string($_POST['direccion']);
estas recogiendo la variable POST direccion con dos c...
y en el formulario:
Código
  1. <input type="text" name="dirrecion">
la tienes con dos r xD

Bueno...he de decir que no estas utilizando REGISTER_GLOBALS ati te ayudaría mucho pero supone ser un problema grave de seguridad por lo tanto no te lo recomiendo...
Te dejo el codigo...

Código
  1. <?php
  2. $bd=mysql_connect("host","jmyname","my pass") or die ("No puedo connectarme a base de datos");
  3. mysql_select_db("database");
  4.  
  5.  
  6. if (isset($_POST['opt']))
  7.  
  8. {
  9.   $nombre=mysql_real_escape_string($_POST['nombre']);
  10.   $email=mysql_real_escape_string($_POST['email']);
  11.   $telefono=mysql_real_escape_string($_POST['telefono']);
  12.   $direccion=mysql_real_escape_string($_POST['direccion']);
  13.   $asunto=mysql_real_escape_string($_POST['asunto']);
  14.  
  15.    mysql_query("INSERT INTO jerbix_lead (nombre, email, telefono, direccion, asunto) VALUES ('".$nombre."', '".$email."', '".$telefono."','".$direccion."','".$asunto."')") or die (mysql_error());
  16. }
  17.  
  18. ?>
  19. <head>
  20. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  21. <title>Untitled Document</title>
  22. <style type="text/css">
  23. <!--
  24. body  {
  25. font: 100% Verdana, Arial, Helvetica, sans-serif;
  26. background: #666666;
  27. margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
  28. padding: 0;
  29. text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
  30. color: #000000;
  31. }
  32. .twoColFixLtHdr #container {
  33. width: 780px;  /* using 20px less than a full 800px width allows for browser chrome and avoids a horizontal scroll bar */
  34. background: #FFFFFF;
  35. margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
  36. border: 1px solid #000000;
  37. text-align: left; /* this overrides the text-align: center on the body element. */
  38. }
  39. .twoColFixLtHdr #header {
  40. background: #DDDDDD;
  41. padding: 0 10px 0 20px;  /* this padding matches the left alignment of the elements in the divs that appear beneath it. If an image is used in the #header instead of text, you may want to remove the padding. */
  42. }
  43. .twoColFixLtHdr #header h1 {
  44. margin: 0; /* zeroing the margin of the last element in the #header div will avoid margin collapse - an unexplainable space between divs. If the div has a border around it, this is not necessary as that also avoids the margin collapse */
  45. padding: 10px 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */
  46. }
  47. .twoColFixLtHdr #sidebar1 {
  48. float: left; /* since this element is floated, a width must be given */
  49. width: 200px; /* the actual width of this div, in standards-compliant browsers, or standards mode in Internet Explorer will include the padding and border in addition to the width */
  50. background: #EBEBEB; /* the background color will be displayed for the length of the content in the column, but no further */
  51. padding: 15px 10px 15px 20px;
  52. }
  53. .twoColFixLtHdr #mainContent {
  54. margin: 0 0 0 250px; /* the left margin on this div element creates the column down the left side of the page - no matter how much content the sidebar1 div contains, the column space will remain. You can remove this margin if you want the #mainContent div's text to fill the #sidebar1 space when the content in #sidebar1 ends. */
  55. padding: 0 20px; /* remember that padding is the space inside the div box and margin is the space outside the div box */
  56. text-align: left;
  57. }
  58. .twoColFixLtHdr #footer {
  59. padding: 0 10px 0 20px; /* this padding matches the left alignment of the elements in the divs that appear above it. */
  60. background:#DDDDDD;
  61. }
  62. .twoColFixLtHdr #footer p {
  63. margin: 0; /* zeroing the margins of the first element in the footer will avoid the possibility of margin collapse - a space between divs */
  64. padding: 10px 0; /* padding on this element will create space, just as the the margin would have, without the margin collapse issue */
  65. }
  66. .fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
  67. float: right;
  68. margin-left: 8px;
  69. }
  70. .fltlft { /* this class can be used to float an element left in your page */
  71. float: left;
  72. margin-right: 8px;
  73. }
  74. .clearfloat { /* this class should be placed on a div or break element and should be the final element before the close of a container that should fully contain a float */
  75. clear:both;
  76.    height:0;
  77.    font-size: 1px;
  78.    line-height: 0px;
  79. }
  80. -->
  81. </style><!--[if IE 5]>
  82. <style type="text/css">
  83. /* place css box model fixes for IE 5* in this conditional comment */
  84. .twoColFixLtHdr #sidebar1 { width: 230px; }
  85. </style>
  86. <![endif]--><!--[if IE]>
  87. <style type="text/css">
  88. /* place css fixes for all versions of IE in this conditional comment */
  89. .twoColFixLtHdr #sidebar1 { padding-top: 30px; }
  90. .twoColFixLtHdr #mainContent { zoom: 1; }
  91. /* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
  92. </style>
  93. <![endif]--></head>
  94.  
  95. <body class="twoColFixLtHdr">
  96.  
  97. <div id="container">
  98.  <div id="header">
  99.    <h1>Reparamos Desktops y Laptops</h1>
  100.  <!-- end #header --></div>
  101.  <div id="sidebar1">
  102.    <!-- end #sidebar1 -->
  103.  </div>
  104.  <div id="mainContent">
  105.    <h1>Solicitud de Servicios</h1>
  106.    <script language="javascript">
  107.  
  108. function verifica()
  109. {
  110.  if (f.email.value=="")
  111.  {
  112.   alert ("por favor ingrese su email");
  113.    return;
  114.  }
  115.  f.opt.value=1
  116.  f.submit();
  117. }
  118.  
  119. </script>
  120.  
  121.    <form name="f" action="" method="post">
  122.    <table width="200" border="0">
  123.      <caption>
  124.      Formulario
  125.      </caption>
  126.      <tr>
  127.        <tr><td width="63">Nombre: <br><input type="text" name="nombre"><input type="hidden" name="opt" /></td></tr>
  128.  <tr><td width="63">Phone Number: <br><input type="text" name="telefono"></td></tr>
  129.  <tr><td width="63">Direccion: <br><input type="text" name="direccion"></td></tr>
  130.  <tr><td width="63">E-mail: <br><input type="text" name="email"></td></tr>
  131.  <tr><td width="63">Asunto <br><textarea name="asunto" rows="4"></textarea>
  132.  </td></tr><tr><td width="63"><input type="button" value="Enviar" onClick="verifica()" /></td></tr></tr>
  133.      </table>
  134.      </form>
  135.  
  136.  
  137.  
  138. <!-- end #mainContent --></div>
  139. <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
  140.  <div id="footer">
  141.    <p>Footer</p>
  142.  <!-- end #footer --></div>
  143. <!-- end #container --></div>
  144. </body>
  145. </html>


Saludos
En línea

pritguy

Desconectado Desconectado

Mensajes: 9


Ver Perfil
Re: PHP y SQL Problemas para hacer un peque~o formulario
« Respuesta #8 en: 8 Mayo 2009, 05:38 am »

ok ahroa tengo una  duda!

Ya Me esta  funcionando :D

pero tengo una pregunta

si por ejemplo quisiera que se mandara un aviso a mi email ? cuando se envia el formulario.

Otra cosa es como yo  puedo decirle al usuario que lo que envio fue enviado correctamente y lo envia para la pagina de inicio?

Busque esto por google pero no me sale .
Código
  1. if (mail(.....)){
  2.  header ("Location: mensajes.php?msg=exito");
  3.  exit;
  4. } else {
  5.  header ("Location: mensajes.php?msg=error");
  6.  exit;
  7. }  
En línea

#!drvy
Moderador
***
Desconectado Desconectado

Mensajes: 5.850



Ver Perfil WWW
Re: PHP y SQL Problemas para hacer un peque~o formulario
« Respuesta #9 en: 9 Mayo 2009, 15:14 pm »

Vale.. lo primero es ver si tu hosting soporta la función "mail" porque si no la soporta difícil lo vas a tener  :¬¬ :¬¬
Otra cosa..te recomiendo que te leas algún manual de PHP de los de hoy en día... porque con copy&paste no se hace nada....

Código
  1. <?php
  2. if(isset($_POST['opt'])) {
  3.    // Conexion Base de datos
  4.    $bd = mysql_connect("sql112.byethost5.com","b5_3150600","s7m6o6k5") or die(mysql_error());
  5.    mysql_select_db("b5_3150600_database",$bd) or die (mysql_error());
  6.  
  7.    // Obtener datos
  8.   $nombre=mysql_real_escape_string($_POST['nombre']);
  9.   $email=mysql_real_escape_string($_POST['email']);
  10.   $telefono=mysql_real_escape_string($_POST['telefono']);
  11.   $direccion=mysql_real_escape_string($_POST['direccion']);
  12.   $asunto=mysql_real_escape_string($_POST['asunto']);
  13.  
  14.   // Crear Registro
  15.    mysql_query("INSERT INTO contact (nombre, email, telefono, direccion, asunto)
  16.     VALUES ('".$nombre."', '".$email."', '".$telefono."','".$direccion."','".$asunto."')") or die (mysql_error());
  17.  
  18.   // Terminar conexion a base de datos
  19.   mysql_close($bd);
  20.  
  21.   // Comprobar si el servidor soporta funcion mail
  22.   if (function_exists('mail')) {
  23.      // Enviar email
  24.  
  25.      $hacia = "bad.stupid.monkey@gmail.com";
  26.      $asunto = "Nuevo Registro";
  27.      $mensaje = "Un nuevo registro fue añadido: <br> Nombre: $nombre <br> Email: $email <br> Telefono: $telefono
  28.      <br> Direccion: $direccion <br> Asunto: $asunto";
  29.      if(mail($to, $subject, $message)) { echo "Su mensaje fue enviado. Gracias 1"; } else {echo "Error en el envio";}
  30.   } else { echo "Su mensaje fue enviado. Gracias 2";}
  31. }
  32. ?>
  33.  
  34. <head>
  35. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  36. <title>Untitled Document</title>
  37. <style type="text/css">
  38. <!--
  39. body  {
  40. font: 100% Verdana, Arial, Helvetica, sans-serif;
  41. background: #666666;
  42. margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
  43. padding: 0;
  44. text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
  45. color: #000000;
  46. }
  47. .twoColFixLtHdr #container {
  48. width: 780px;  /* using 20px less than a full 800px width allows for browser chrome and avoids a horizontal scroll bar */
  49. background: #FFFFFF;
  50. margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
  51. border: 1px solid #000000;
  52. text-align: left; /* this overrides the text-align: center on the body element. */
  53. }
  54. .twoColFixLtHdr #header {
  55. background: #DDDDDD;
  56. padding: 0 10px 0 20px;  /* this padding matches the left alignment of the elements in the divs that appear beneath it. If an image is used in the #header instead of text, you may want to remove the padding. */
  57. }
  58. .twoColFixLtHdr #header h1 {
  59. margin: 0; /* zeroing the margin of the last element in the #header div will avoid margin collapse - an unexplainable space between divs. If the div has a border around it, this is not necessary as that also avoids the margin collapse */
  60. padding: 10px 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */
  61. }
  62. .twoColFixLtHdr #sidebar1 {
  63. float: left; /* since this element is floated, a width must be given */
  64. width: 200px; /* the actual width of this div, in standards-compliant browsers, or standards mode in Internet Explorer will include the padding and border in addition to the width */
  65. background: #EBEBEB; /* the background color will be displayed for the length of the content in the column, but no further */
  66. padding: 15px 10px 15px 20px;
  67. }
  68. .twoColFixLtHdr #mainContent {
  69. margin: 0 0 0 250px; /* the left margin on this div element creates the column down the left side of the page - no matter how much content the sidebar1 div contains, the column space will remain. You can remove this margin if you want the #mainContent div's text to fill the #sidebar1 space when the content in #sidebar1 ends. */
  70. padding: 0 20px; /* remember that padding is the space inside the div box and margin is the space outside the div box */
  71. text-align: left;
  72. }
  73. .twoColFixLtHdr #footer {
  74. padding: 0 10px 0 20px; /* this padding matches the left alignment of the elements in the divs that appear above it. */
  75. background:#DDDDDD;
  76. }
  77. .twoColFixLtHdr #footer p {
  78. margin: 0; /* zeroing the margins of the first element in the footer will avoid the possibility of margin collapse - a space between divs */
  79. padding: 10px 0; /* padding on this element will create space, just as the the margin would have, without the margin collapse issue */
  80. }
  81. .fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
  82. float: right;
  83. margin-left: 8px;
  84. }
  85. .fltlft { /* this class can be used to float an element left in your page */
  86. float: left;
  87. margin-right: 8px;
  88. }
  89. .clearfloat { /* this class should be placed on a div or break element and should be the final element before the close of a container that should fully contain a float */
  90. clear:both;
  91.    height:0;
  92.    font-size: 1px;
  93.    line-height: 0px;
  94. }
  95. -->
  96. </style><!--[if IE 5]>
  97. <style type="text/css">
  98. /* place css box model fixes for IE 5* in this conditional comment */
  99. .twoColFixLtHdr #sidebar1 { width: 230px; }
  100. </style>
  101. <![endif]--><!--[if IE]>
  102. <style type="text/css">
  103. /* place css fixes for all versions of IE in this conditional comment */
  104. .twoColFixLtHdr #sidebar1 { padding-top: 30px; }
  105. .twoColFixLtHdr #mainContent { zoom: 1; }
  106. /* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
  107. </style>
  108. <![endif]--></head>
  109.  
  110. <body class="twoColFixLtHdr">
  111.  
  112. <div id="container">
  113.  <div id="header">
  114.    <h1>Reparamos Desktops y Laptops</h1>
  115.  <!-- end #header --></div>
  116.  <div id="sidebar1">
  117.    <!-- end #sidebar1 -->
  118.  </div>
  119.  <div id="mainContent">
  120.    <h1>Solicitud de Servicios</h1>
  121.    <script language="javascript">
  122.  
  123. function verifica()
  124. {
  125.  if (f.email.value=="")
  126.  {
  127.   alert ("Por favor ingrese su email");
  128.    return;
  129.  }
  130.  f.opt.value=1
  131.  f.submit();
  132. }
  133.  
  134. </script>
  135.  
  136.    <form name="f" action="" method="post">
  137.    <table width="200" border="0">
  138.      <caption>
  139.      Formulario
  140.      </caption>
  141.      <tr>
  142.        <tr><td width="63">Nombre: <br><input type="text" name="nombre"><input type="hidden" name="opt" /></td></tr>
  143.  <tr><td width="63">Phone Number: <br><input type="text" name="telefono"></td></tr>
  144.  <tr><td width="63">Direccion: <br><input type="text" name="direccion"></td></tr>
  145.  <tr><td width="63">E-mail: <br><input type="text" name="email"></td></tr>
  146.  <tr><td width="63">Asunto <br><textarea name="asunto" rows="4"></textarea>
  147.  </td></tr><tr><td width="63"><input type="button" value="Enviar" onClick="verifica()" /></td></tr></tr>
  148.      </table>
  149.      </form>
  150.  
  151.  
  152.  
  153. <!-- end #mainContent --></div>
  154. <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
  155.  <div id="footer">
  156.    <p>Footer</p>
  157.  <!-- end #footer --></div>
  158. <!-- end #container --></div>
  159. </body>
  160. </html>
  161.  
Intenta comprenderlo y no le hagas copy&paste directamente.

Saludos
En línea

Páginas: [1] 2 Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Una pequeña duda ( se me olvido jaja )
Foro Libre
BlackZeroX 5 2,429 Último mensaje 9 Febrero 2011, 05:04 am
por Roy-Mustang
problemas con un formulario
Desarrollo Web
danicasasm 0 1,418 Último mensaje 22 Abril 2012, 14:37 pm
por danicasasm
El mejor regalo para el 'peque': todo un ordenador por sólo 100 dólares
Noticias
wolfbcn 0 1,140 Último mensaje 20 Diciembre 2013, 01:42 am
por wolfbcn
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines