Ver Mensaje Individual
  #16 (permalink)  
Antiguo 14/01/2016, 08:45
x_atrix
 
Fecha de Ingreso: enero-2016
Mensajes: 71
Antigüedad: 8 años, 3 meses
Puntos: 14
Respuesta: Error php con mysql

No puede ser porque $conectar es nulo ...

Código PHP:
Ver original
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <title></title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <link type="text/css" href="css/sunny/jquery-ui-1.8.13.custom.css" rel="stylesheet" />
  8. <script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
  9. <script type="text/javascript" src="js/jquery-ui-1.8.13.custom.min.js"></script>
  10. <script type="text/javascript">
  11.  
  12. $(function() {
  13. $( ".datepicker" ).datepicker();
  14. });
  15. </script>
  16. <body>
  17. <form id="form" name="form" method="post">
  18. Fecha Inicio:
  19. <input type="text" name="fechaIni" class="datepicker">
  20. <br>
  21. Fecha Final:
  22. <input type="text" name="fechaFin" class="datepicker">
  23. <br>
  24. <input type="submit" value="Consultar">
  25. </form>
  26. <h1>Consultas</h1>
  27.  
  28. <?php
  29. function js2PhpTime($jsdate){
  30. if(preg_match('@(\d+)/(\d+)/(\d+)\s+(\d+):(\d+)@', $jsdate, $matches)==1){
  31. $ret = mktime($matches[4], $matches[5], 0, $matches[1], $matches[2], $matches[3]);
  32. //echo $matches[4] ."-". $matches[5] ."-". 0 ."-". $matches[1] ."-". $matches[2] ."-". $matches[3];
  33. }else if(preg_match('@(\d+)/(\d+)/(\d+)@', $jsdate, $matches)==1){
  34. $ret = mktime(0, 0, 0, $matches[1], $matches[2], $matches[3]);
  35. //echo 0 ."-". 0 ."-". 0 ."-". $matches[1] ."-". $matches[2] ."-". $matches[3];
  36. }
  37. //return $ret;
  38. }
  39. //echo date("Y-m-d", js2PhpTime('08/02/2011'));
  40. $fechaIni="";
  41. if (isset($_POST['fechaIni'])) {$fechaIni = $_POST['fechaIni'];}
  42.  
  43. $fechaFin="";
  44. if (isset($_POST['fechaFin'])) {$fechaFin = $_POST['fechaFin'];}
  45.  
  46. //$fechaMySQLFin = $_POST[implode( '-', array_reverse( explode( '/', $fechaFin ) ) )] ;
  47. $Inicio=date("Y-m-d", js2PhpTime($fechaIni));
  48. $Final=date("Y-m-d", js2PhpTime($fechaFin));
  49. $conectar=mysql_connect('localhost','root','');
  50. if($conectar==null)
  51. {
  52. printf("Error al conectar a la Base de datos");
  53. die();
  54. }
  55.  
  56. mysql_select_db('resumenbeta');
  57. echo $fechaIni;
  58. $resultado=mysql_query("SELECT Fecha, TipoDeProduccion, Pais, Cliente FROM resumenbeta WHERE Fecha BETWEEN '$Inicio' AND '$Final'");
  59.  
  60. if($row=mysql_fetch_array($resultado)){
  61. echo "<table border='1' align='center'>\n";
  62. echo "<tr><td>Fecha</td><td>TipoDeProducto</td><td>Pais</td><td>Cliente</td></tr> \n";
  63. do{
  64.  
  65. echo "<tr><td>".$row["Fecha"]."</td><td>".$row["TipoDeProducto"]."</td><td>".$row["Pais"]."</td><td>".$row["Cliente"]."</td></tr> \n";
  66. }while($row=mysql_fetch_array($resultado));
  67. echo "</table>\n";
  68. }
  69. else{
  70. echo "<center>No existen registros para el rango de esas fechas</center>";
  71. }
  72.  
  73. ?>
  74.  
  75.  
  76. </body>
  77. </html>