Foros del Web » Programando para Internet » PHP »

como inserta html a mysql y cmo sacarlo despues

Estas en el tema de como inserta html a mysql y cmo sacarlo despues en el foro de PHP en Foros del Web. estoy tratando de meter código de html a mysql y despue sacarlo y no he podido esta es la pagina principal donde inserto los campos ...
  #1 (permalink)  
Antiguo 25/07/2013, 19:54
Avatar de jor_0203  
Fecha de Ingreso: octubre-2011
Ubicación: mexico
Mensajes: 760
Antigüedad: 12 años, 6 meses
Puntos: 8
como inserta html a mysql y cmo sacarlo despues

estoy tratando de meter código de html a mysql y despue sacarlo y no he podido
esta es la pagina principal donde inserto los campos

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Documento sin t&iacute;tulo</title>
  5. <script type="text/javascript">
  6. function variable()
  7. {
  8. u=document.getElementById("contenido").innerHTML;
  9. contac.H.value=u;
  10. }
  11. </head>
  12. <form action="a2.php" method="post" onmouseover="javascript:( variable());" name="contac">
  13. <input name="nombre" type="text"  />
  14. <input name="H" type="hidden" value="" />
  15. <div id="contenido" contenteditable="true" >Este es un texto donde va el html y después lo manda  </div>
  16. <input type="submit" value="buoton"  />
  17. </form>
  18. </body>
  19. </html>


y esta es la pagina que recibe



Código PHP:
Ver original
  1. <?php
  2. mysql_connect('localhost','root','');
  3. mysql_select_db('diveditable');
  4. $a=$_POST['H'];
  5. $r=$_POST['nombre'];
  6. //$t=nl2br(htmlspecialchars($h)); tambien lo hice de esta forma
  7. mysql_query("INSERT INTO nombre (nombre, hola) VALUES ( '$r', '$a')");
  8. //nombre es el campo de la tabla
  9. $t=mysql_query("select nombre, hola from nombre");
  10. while($TT=mysql_fetch_array($t)){
  11. echo $TT[0];
  12. $j=nl2br(htmlspecialchars($TT[1]));
  13. echo $j;
  14. echo "<br />";
  15. }
  16. ?>


y esto es lo que me sale cuando trato de imprimir
ojala alguien sepa como puedo hacerlo
mil gracias


&lt;div&gt;&amp;lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtm...t;&amp;lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&amp;gt;&lt;/d...t;&amp;lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;lt;title&amp;gt;Documento sin t&amp;amp;iacute;tulo&amp;lt;/title&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;lt;/head&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;lt;body&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;lt;script language=javascript&amp;gt;&lt;/div&gt;&lt;div&gt;function a(){&lt;/div&gt;&lt;div&gt;open(&quot;http://www.google.com.mx&quot;,&quot;test&quot;,&quot;hei ght=200,width=200,location=true&quot;);&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&amp;lt;/script&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;lt;a href=&quot;#&quot; onclick=&quot;a();&quot;&amp;gt;hola&amp;lt;/a&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;lt;a href=&quot;#&quot; onclick=&quot;b();&quot;&amp;gt;hola&amp;lt;/a&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;lt;script language=javascript&amp;gt;&lt;/div&gt;&lt;div&gt;function b()&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;var a=open(&quot;http://www.google.com.mx&quot;,&quot;test&quot;,&quot;he...ose();&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&amp;lt;/script&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;lt;/body&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;
  #2 (permalink)  
Antiguo 25/07/2013, 19:58
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: como inserta html a mysql y cmo sacarlo despues

Al guardar el HTML deberías decodificarlo para recuperar su formato original, o también al imprimirlo, es igual pero si lo haces antes de guardar ahorras bytes.

Consulta html_entity_decode() en el manual:

http://php.net/manual/es/function.ht...ity-decode.php
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 25/07/2013, 19:59
Avatar de herran1212  
Fecha de Ingreso: julio-2013
Ubicación: cali
Mensajes: 89
Antigüedad: 10 años, 9 meses
Puntos: 3
Respuesta: como inserta html a mysql y cmo sacarlo despues

holas, en la aprte del codigo php te falta crear bien la conexion, y en el mysql_query debe ir la cadena sql con el objeto de conexion
  #4 (permalink)  
Antiguo 28/07/2013, 20:28
Avatar de jor_0203  
Fecha de Ingreso: octubre-2011
Ubicación: mexico
Mensajes: 760
Antigüedad: 12 años, 6 meses
Puntos: 8
Respuesta: como inserta html a mysql y cmo sacarlo despues

Cita:
Iniciado por pateketrueke Ver Mensaje
Al guardar el HTML deberías decodificarlo para recuperar su formato original, o también al imprimirlo, es igual pero si lo haces antes de guardar ahorras bytes.

Consulta html_entity_decode() en el manual:

http://php.net/manual/es/function.ht...ity-decode.php
me gustaria saber su opinion si es que esto esta mal o esta bien gracias
Código PHP:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Documento sin t&iacute;tulo</title>
  6. <script type="text/javascript">
  7. function variable()
  8. {
  9. u=document.getElementById("contenido").innerHTML;
  10. contac.H.value=u;
  11. }
  12. </script>
  13. </head>
  14. <body>
  15. <form action="recibe.php" method="post" onmouseover="javascript:( variable());" name="contac">
  16. <input name="nombre" type="text"  />
  17. <input name="H" type="hidden" value="" />
  18. <div id="contenido" contenteditable="true" >Este es un texto </div>
  19. <input type="submit" value="buoton"  />
  20. </form>
  21. </body>
  22. </html>

esta es la pagina recibe.php
Código PHP:
Ver original
  1. <?php
  2. mysql_connect('localhost','root','');
  3. mysql_select_db('diveditable');
  4. $a=$_POST['H'];
  5. $r=$_POST['nombre'];
  6. $b=htmlentities($a);
  7. mysql_query("INSERT INTO nombres (nombre,hola)VALUES('$r', '$b')");
  8. $t=mysql_query("select nombre, hola from nombres");
  9. while($TT=mysql_fetch_array($t))
  10. {
  11. echo $TT[0];
  12. $j=html_entity_decode($TT[1]);
  13. echo $j;
  14. echo "<br />";
  15. }
  16. ?>
  #5 (permalink)  
Antiguo 28/07/2013, 20:31
Avatar de jor_0203  
Fecha de Ingreso: octubre-2011
Ubicación: mexico
Mensajes: 760
Antigüedad: 12 años, 6 meses
Puntos: 8
Respuesta: como inserta html a mysql y cmo sacarlo despues

me gustaria saber su opinion si es que esto esta mal o esta bien gracias
Código PHP:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Documento sin t&iacute;tulo</title>
  6. <script type="text/javascript">
  7. function variable()
  8. {
  9. u=document.getElementById("contenido").innerHTML;
  10. contac.H.value=u;
  11. }
  12. </script>
  13. </head>
  14. <body>
  15. <form action="recibe.php" method="post" onmouseover="javascript:( variable());" name="contac">
  16. <input name="nombre" type="text"  />
  17. <input name="H" type="hidden" value="" />
  18. <div id="contenido" contenteditable="true" >Este es un texto </div>
  19. <input type="submit" value="buoton"  />
  20. </form>
  21. </body>
  22. </html>

esta es la pagina recibe.php
Código PHP:
Ver original
  1. <?php
  2. mysql_connect('localhost','root','');
  3. mysql_select_db('diveditable');
  4. $a=$_POST['H'];
  5. $r=$_POST['nombre'];
  6. $b=htmlentities($a);
  7. mysql_query("INSERT INTO nombres (nombre,hola)VALUES('$r', '$b')");
  8. $t=mysql_query("select nombre, hola from nombres");
  9. while($TT=mysql_fetch_array($t))
  10. {
  11. echo $TT[0];
  12. $j=html_entity_decode($TT[1]);
  13. echo $j;
  14. echo "<br />";
  15. }
  16. ?>

Etiquetas: html, inserta, mysql, select, sql, tabla, variable
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 04:22.