Ver Mensaje Individual
  #6 (permalink)  
Antiguo 13/04/2011, 08:48
konvulsion
 
Fecha de Ingreso: abril-2011
Mensajes: 39
Antigüedad: 13 años
Puntos: 1
Respuesta: No logro hacer un query del último id

Reinicializo mi pregunta... Voy a hacer varias preguntas, la 1era es la que me gustaría resolver en 1er término, y las otras me gustaría resolverlas en la medida de lo posible, pero tampoco espero ni mucho menos que me respondáis a todo.

1- No consigo obtener mi última id (inserción) de mi base de datos MySql para poder operar posteriormente con ella en PHP.

2- Me gustaría saber cómo transformar en hipervínculo el texto de un formulario (o sea, una inserción de texto) antes de darle al botón de enviar (submit)... o hacer lo que sea para que al hacer el submit se transforme en hipervínculo.

3- Me gustaría saber qué tendría que hacer para que ese hipervínculo fuera el "get" de un formulario (entonces el usuario pincharía ahí con el ratón y le llevaría a una página tipo http://www.mipagina.com/formulario.php1234).


El código entero es este:


Código PHP:
Ver original
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  4. <title></title>
  5. </head>
  6. <body>
  7. <?php
  8. function Conectarse()
  9. {
  10. if (!($link=mysql_connect("x.x.x","x","x")))
  11. {
  12. echo "Error conectando a la base de datos.";
  13. exit();
  14. }
  15. if (!mysql_select_db("x",$link))
  16. {
  17. echo "Error seleccionando la base de datos.";
  18. exit();
  19. }
  20. return $link;
  21. }
  22.  
  23. $link=Conectarse();
  24. /*echo "Conexión con la base de datos conseguida.<br>";*/
  25. mysql_close($link); //cierra la conexion
  26. ?>
  27. </body>
  28. </html>
  29.  
  30.  
  31.  
  32. <html xmlns="http://www.w3.org/1999/xhtml">
  33.  
  34. <head>
  35. </head>
  36. <body>
  37. <?php
  38. $nombre=$_POST['nombre'];
  39. $email=$_POST['email'];
  40. $categori=$_POST['categori'];
  41.  
  42. {
  43. mysql_connect("x","x","x");
  44.  
  45. mysql_query("INSERT INTO tabla(nombre,email,categori) VALUES('$nombre','$email','$categori')");
  46.  
  47. }
  48. ?>
  49. <form id="form1" name="form1" method="post" action="" onclick="this.value=''">
  50. <input name="categori" input type="hidden" type="text" id="categori" value="prueba" size="15">
  51. <table cellpadding="0" cellspacing="0" width="607" height="178">
  52. <!-- MSTableType="layout" -->
  53. <tr>
  54. <td valign="top" height="178" width="607">
  55. <table width="607" border="1">
  56. <tr>
  57. <td width="160">Nombre</td>
  58. <td width="431">
  59. <input name="nombre" type="text" id="nombre" value="Tu nombre" size="20" onclick="this.value=''"/></td>
  60. </tr>
  61. <tr>
  62. <td>texto</td>
  63. <td><label>
  64. <input name="email" type="text" id="email" size="96" />
  65. </label></td>
  66. </tr>
  67. <tr>
  68. <td width="160">Categor</td>
  69. <td width="431">
  70. &nbsp;</td>
  71. </tr>
  72. <tr>
  73. <td height="23">&nbsp;</td>
  74. <td height="23">
  75. &nbsp;
  76. <select name="prueba" onchange="javascript:document.form1.categori.value =(document.form1.prueba.value)">
  77. <option value="Categoría">Categoría</option>
  78. <option value='<a href="http://www.url.com/directorio/muñecas.php">muñecas</a>'>Muñecas</option>
  79. <option value='<a href="http://www.url.com/directorio/ositos.php">ositos</a>'>Ositos</option>
  80. <option value='<a href="http://www.url.com/directorio/juguetes.php">juguetes</a>'>Juguetes</option>
  81.  
  82. </select>
  83. </td>
  84. </tr>
  85. <tr>
  86. <td height="23">&nbsp;</td>
  87. <td height="23">
  88. <p align="center"><input type="submit" value="Enviar" name="Enviar"></td>
  89. </tr>
  90. <tr>
  91. <td height="23">&nbsp;</td>
  92. <td height="23">
  93.  
  94. &nbsp;</td>
  95. </tr>
  96. </table>
  97. </form>
  98.  
  99. </tr>
  100. </table>
  101. <p>&nbsp;</p>
  102.  
  103. <table border="0" cellspacing=10 cellpadding=0 style="font-size: 8pt"><tr>
  104. <td><font face="verdana"><b>Id</b></font></td>
  105. <td><font face="verdana"><b>Nombre</b></font></td>
  106. <td><font face="verdana"><b>texto</b></font></td>
  107. <td><font face="verdana"><b>categori</b></font></td>
  108.  
  109. </tr>
  110.  
  111. <?php
  112. $link = @mysql_connect("x","x","x")
  113. or die ("Error al conectar a la base de datos.");
  114. @mysql_select_db("x", $link)
  115. or die ("Error al conectar a la base de datos.");
  116.  
  117. $query = "SELECT f.id, f.nombre, f.email, f.categori " .
  118. "FROM tabla f " .
  119. "WHERE f.email NOT IN ('Europa')";
  120. $result = mysql_query($query);
  121. $numero = 0;
  122.  
  123. while($row = mysql_fetch_array($result))
  124. {
  125. echo "<tr><td width=\"25%\"><font face=\"verdana\">" .
  126. $row["id"] . "</font></td>";
  127. echo "<td width=\"25%\"><font face=\"verdana\">" .
  128. $row["nombre"] . "</font></td>";
  129. echo "<td width=\"25%\"><font face=\"verdana\">" .
  130. $row["email"] . "</font></td>";
  131. echo "<td width=\"25%\"><font face=\"verdana\">" .
  132. $row["categori"] . "</font></td>";
  133. }
  134.  
  135. mysql_close($link);
  136. ?>
  137. </table>


Gracias por vuestras respuestas.