PHP - Error: Uncaught SyntaxError: Unexpected token <

 
Vista:

Error: Uncaught SyntaxError: Unexpected token <

Publicado por Javier (2 intervenciones) el 10/03/2018 18:46:33
Buenas, estoy aprendiendo html, php y js haciendo una pequeña web. El problema que tengo es el siguiente:
He creado un template de login, y en el caso de login correcto quiero que me redirija a la pag index.php (adjunto codigo ahora). Lo que quiero que haga esta pagina es que me muestre un mapa y me pinte unos marcadores de unos puntos que saco de una base de datos.
Pero al probarlo me da error en la linea donde defino el codigo php. El error es el adjuntado en el titulo. Error: Uncaught SyntaxError: Unexpected token <


Adjunto el código por si les sirve de ayuda.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html>
  <head>
    <title>Simple Map</title>
    <meta name="viewport" content="initial-scale=1.0">
    <meta charset="utf-8">
    <style>
      /* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
      #map {
        height: 100%;
      }
      /* Optional: Makes the sample page fill the window. */
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
    </style>
  </head>
  <body>
 
    <div id="map"></div>
    <script>
      var map;
      function initMap() {
        map = new google.maps.Map(document.getElementById('map'), {
          center: {lat: 40.416775, lng: -3.7037901999999576},
          zoom: 6
        });
        var myLatlng = new google.maps.LatLng(41,-3.7);
        var marker = new google.maps.Marker({
        position: myLatlng});
        marker.setMap(map);
        addAddresToMap(42,-4, map);
      }
    </script>
    <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBHHg1xGO02ABfacesM0rpV01ufak3oBo0s&callback=initMap"
    async defer></script>
    <script>
      function addAddresToMap(latitud,longitud, map) {
        var myLatlng = new google.maps.LatLng(latitud,longitud);
        var marker = new google.maps.Marker({
        position: myLatlng});
        marker.setMap(map);
      }
    </script>
</body>
<?php  ----> ERROR en esta linea
    session_start();
    ?>
    <?php
    include("config.php");
    $conexion = new mysqli($host_db, $user_db, $pass_db, $db_name);
    if ($conexion->connect_error) {
    die("La conexion falló: " . $conexion->connect_error);
    }
    $sql = "SELECT * FROM addres";
    $result= $conexion->query($sql);
    $map = "<script> document.write(map) </script>";
    while (($fila = mysqli_fetch_array($result))!=NULL){
        $longitud = $fila['longitud'] ;
        $latitud =  $fila['latitud'] ;
        echo "<script language='javascript'> addAddresToMap(".$longitud.",".$latitud.",".$map.") </script>";
        echo "\n";
    }
    ?>
</html>


Muchas gracias de antemano. Un saludo
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Error: Uncaught SyntaxError: Unexpected token <

Publicado por xve (6935 intervenciones) el 11/03/2018 19:15:32
Hola Javier, he probado tu código cambiando la linea:
1
<?php ----> ERROR en esta linea
por
1
<?php

y todo me ha ido perfectamente!!! me da un error la key de google maps pero no el php!!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Error: Uncaught SyntaxError: Unexpected token <

Publicado por javier (2 intervenciones) el 12/03/2018 08:21:33
Muchas gracias, ya lo he solucionado, siii daba un error en el API key, había copiado mal una letra, muchas gracias por contestar.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar