Alternative to StackExchange for Arduino simple PHP programing

Hello, I need someone to suggest a forum that is kind, like the Arduino forum where I can ask questions about simple PHP programing.
I tried StackExchange, but it always give me the impression, that they don't want to help, just bash everyone.

I'm having a simple Google Maps API problem, that I guess, someone who knows a little, might find the coding error.

Thank you.

There are many who say that about this forum!

There are those here who know PHP, including myself, but I don't know if there are any experts. There are, however, many programming experts, and programming is, after all, programming.

So post your code and details/evidence of the bug

1 Like

Many web content fora cover php, asp, et c.
https://forum.phpwcms.org/

flag

1 Like

Great, the problem I'm having is that the maps dissapear, and I have to reaload the page , sometimes 4 to 5 times and then works.
Chrome says that I've 1 error and 1 possible improvement.
I know that the map is shaded because of the Credit card payment, but I think that's not the problem.
The improvement is about Quirks mode, I tried modifying the htacces on the server to include php so that i can name the DOCTYPE as HTML but, it didn't work.

The code from "index.php" :

<?php 
session_start();

	include("connection.php");
	include("functions.php");

	$user_data = check_login($con);

?>

<?php 

include 'getstate.php';

?>

  <html>
    <head>
        <meta name="viewport" content width="devide-width, initial-scale=1.0">
        <title>Sistema de gestión de balizas</title>
            <link rel="stylesheet" href="style.css">
        </head>
<body>
    
        <div class="split left">
            
  <div class="left">
      
      <h1 style="text-align:center"> Sistema de gestión de balizas</h1>
      
      <hr class="solid"> 
      
     <br>
<form action="save.php" method="post">
Identificador: <input type="text" name="identificador"><br>
Intensidad: <input type="text" name="green"><br>
Tiempo prendida (0 - 5 ): <input type="text" name="yellow"><br>
Tiempo apagada  (0 - 5): <input type="text" name="blue"><br>

<input type="submit" value="Enviar"> 
</form>

 <hr class="solid">
 
  <p> Identificador :
  <?php 

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT State FROM ledStatus WHERE Color= 'identificador'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo  $row["State"];
        
        if ($row["State"]==0){
                echo " " ." - Baliza principal";
        }
            else {
                echo " " ." - Baliza auxiliar";
                }
        
            }
        }

$conn->close();

?>	

<hr class="solid">

 <p> Voltaje de la batería de la baliza :
 
 <?php 

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
                } 

$sql = "SELECT State FROM ledStatus WHERE Color= 'identificador'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    
    // output data of each row
    
    while($row = $result->fetch_assoc()) {
        //echo  $row["State"];
        
        if ($row["State"]==0){
$sql = "SELECT voltaje1 FROM tbl_gps ORDER BY id DESC LIMIT 1";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    
    while($row = $result->fetch_assoc()) {
        echo  $row["voltaje1"];
        
            }
        }
                
//echo " " ." - Baliza principal";
        }
            else {
$sql = "SELECT voltaje2 FROM tbl_gps ORDER BY id DESC LIMIT 1";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    
    // output data of each row
    
    while($row = $result->fetch_assoc()) {
        echo  $row["voltaje2"];
        
            }
        }
//echo " " ." - Baliza auxiliar";
                }
        
            }
        }

$conn->close();

echo " "
?>
V

<hr class="solid">
 
 <p> Cadencia:   
  <?php 

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT State FROM ledStatus WHERE Color= 'yellow'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        // echo  $row["State"];
        
        if ($row["State"]==0){
                echo " " ." 0 ms Encendida ";
        }
            else if($row["State"]==1) {
                echo " " ." 100 ms Encendida ";
                }
            else if($row["State"]==2) {
                echo " " ." 200 ms Encendida ";
                }
            else if($row["State"]==3) {
                echo " " ." 500 ms Encendida ";
                }    
            else if($row["State"]==4) {
                echo " " ." 800 ms Encendida ";
                }
            else if($row["State"]==5) {
                echo " " ." 1000 ms Encendida ";
                }
            }
        }

$sql = "SELECT State FROM ledStatus WHERE Color= 'blue'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        //echo  $row["State"];
        
        if ($row["State"]==0){
                echo " " ." - 0 ms Apagada ";
        }
            else if($row["State"]==1) {
                echo " " ." - 100 ms Apagada ";
                }
            else if($row["State"]==2) {
                echo " " ." - 200 ms Apagada ";
                }
            else if($row["State"]==3) {
                echo " " ." - 500 ms Apagada ";
                }    
            else if($row["State"]==4) {
                echo " " ." - 800 ms Apagada ";
                }
            else if($row["State"]==5) {
                echo " " ." - 1000 ms Apagada ";
                }
            }
        }
        
$conn->close();

?>	

<hr class="solid">

<p> Intensidad (Lm):

<?php 

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 


$sql = "SELECT State FROM ledStatus WHERE Color= 'green'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo  $row["State"];
        
        if ($row["State"]==0){
                echo " " ." - 0 mcd";
        }
            else if ($row["State"]==1){
                echo " " ." - 1000 mcd";
                }
                else if ($row["State"]==2){
                echo " " ." - 2000 mcd";
                }
                else if ($row["State"]==3){
                echo " " ." - 3000 mcd";
                }
                else if ($row["State"]==4){
                echo " " ." - 4000 mcd";
                }
                else if ($row["State"]==5){
                echo " " ." - 5000 mcd";
                }
            }
        }
        
    


$conn->close();

?>	

<hr class="solid">

<p> Estado de la baliza: 

<?php 

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 


$sql = "SELECT State FROM ledStatus WHERE Color= 'green'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo  $row["State"];
        
        if ($row["State"]==0){
                echo " " ." - La baliza esta apagada";
        }
            else {
                echo " " ." - La baliza esta prendida";
                }
            }
        }
        
    


$conn->close();

?>	


<hr class="solid">

<p> Latitud: 
    <?php 

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT lat FROM tbl_gps ORDER BY id DESC LIMIT 1";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo  $row["lat"];
        
            }
        }
        
    


$conn->close();

?>	

    
<hr class="solid">

<p> Longitud: 

<?php 

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 


$sql = "SELECT lng FROM tbl_gps ORDER BY id DESC LIMIT 1";

$result = $conn->query($sql);
if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo  $row["lng"];
        
            }
        }
        
    


$conn->close();

?>	

<hr class="solid">

<p> Estado de conexión (Red Celular o LoRa): 
 <?php 

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT State FROM ledStatus WHERE Color= 'identificador'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo  $row["State"];
        
        if ($row["State"]==0){
                echo " " ." - Red Celular";
        }
            else {
                echo " " ." - LoRa";
                }
        
            }
        }

$conn->close();

?>	
    
<hr class="solid">

<p> Usuario registrado como:<?php echo $user_data['user_name']; ?> </p>
<p>Para salir : <a href="logout.php">Logout</a> </p>

<hr class="solid">

  </div>
</div>

<div class="split right">
    
  <div class="end">
    
<?php

require 'config.php';

$sql = "SELECT * FROM tbl_gps WHERE 1";
$result = $db->query($sql);
if (!$result) {
  { echo "Error: " . $sql . "<br>" . $db->error; }
}

$rows = $result -> fetch_all(MYSQLI_ASSOC);


?>
<html>
    <head>
           
          <h1 style="text-align:center"> Ubicación de las balizas</h1>
          
    </head>

<style>

/* 
 * Optional: Makes the sample page fill the window. 
 */
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: Arial;
    }

/* 
 * Always set the map height explicitly to define the size of the div element
 * that contains the map. 
 * Margin(vertical,horizontal)
 * max-width(el ancho del mapa)
 * min-height (el alto minimo del mapa)
 */

#map-layer {
	height: 60%;
	margin: 40px 40px; 
	max-width: 600px;
	min-height: 100;
    }

</style>

<body>

    	<div id="map-layer"></div>

	<script
		src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBKXiCf4p90xhFm-MugEJVk3_FMdGTrajA&callback=initMap"
		async defer></script>
		
        <script>
      
      var map;
      
      function initMap() {
        
        var mapLayer = document.getElementById("map-layer");
		var centerCoordinates = new google.maps.LatLng(48.8685,2.3045);
		var defaultOptions = { center: centerCoordinates, zoom: 10 }

		map = new google.maps.Map(mapLayer, defaultOptions);


<?php foreach($rows as $location){ ?>
        var location = new google.maps.LatLng(<?php echo $location['lat']; ?>, <?php echo $location['lng']; ?>);
        var marker = new google.maps.Marker({
            position: location,
            map: map
        });
    <?php } ?>
        
      }
        </script>
      </body>
</html>
        
        
        
    </div>
    </div>
  </div>
</div>
    </body>
</html>

Here is the code from "style.css" :

*
{
    margin :1;
    padding :0;
    box-sizing:border-box;
    font-family:'Poppins', sans-serif ;
    margin-bottom:20px;
}
.container {
    width:100%;
    height:100vh;
    display:flex;
    align-items:flex-end;
    justify-content:flex-end;
    flex-direction:column;
    
    
}
h1{
    color:#333;
    margin-bottom:20px;
    align-items:center;
    justify-content:center;
}
iframe {
    width:120%;
    height:400px;
}

/* Split the screen in half */
.split {
  height: 100%;
  width: 50%;
  position: fixed;
  z-index: 1;
  top: 0;
  overflow-x: hidden;
  padding-top: 20px;
}

/* Control the left side */
.left {
  left: 0;
  background-color: lightgreen;
}

/* Control the right side */
.right {
  right: 0;
  background-color: blue;
}

/* If you want the content centered horizontally and vertically */
.centered {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  text-align: center;
}

/* Style the image inside the centered container, if needed */
.centered img {
  width: 150px;
  border-radius: 50%;
}

/* Solid border */

.solid {
  border-top: 3px solid #bbb;
}

/* 
 * 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;
}

File "htaccess" :


# HTID:21410327: DO NOT REMOVE OR MODIFY THIS LINE AND THE LINES BELOW
php_value display_errors 1
# DO NOT REMOVE OR MODIFY THIS LINE AND THE LINES ABOVE HTID:21410327:

AddType application/x-httpd-php .html


One thing I noticed is that if I clear the History/Cookies it works fine.






Thank you for your help.

Thank you, I'll post in that forum then if no one can help here.

Look for WCMS (web content management systems - website environments like joomla, drupal) and their communities for PHP. I dropped out of websites at the turn of the century, but learned from the communities.

Hmmm... that's a lot of code!

What is your level of experience with PHP, and how much of this code did you write yourself or copy from others and merge together? How many stages of development and testing did you take to do this?

The code you posted has some of the hallmarks of a beginner "biting off now than they can chew" at one go. For example, the indentation is a mess, there seems to be some duplication and some unnecessary lines.

As a beginner, you should not copy any code you don't fully understand, at line level of detail. You should start as simple as possible, test, add 1 more feature, test, add another feature, test, and so on. At each stage, review the code you have and try to find parts which are repetitive and then find ways to remove them. Always be searching for ways to simplify your code. With code, less it better (within reason).

These principles apply to coding in any language.

Sorry this is very general advice, but it will take anyone a long time to digest and understand all the code you posted in detail.

A useful technique in your situation is to create a minimum but complete example code that demonstrates the problem. Remove anything from it that is not required to reproduce the problem. Often, in the process of creating this example, you will may well discover the cause of the problem. If not, you can post the minimum example in a forum like this and it is much more likely that other forum members will have the time to read it and understand it and perhaps spot the cause of the problem.

1 Like

I wrote it all...
I was adding bit by bit of code, and the whole page was running fine. The problem started when I added the GoogleMaps to the right vertical page div.

Really you can take all the left part out and the problem persist...let me show you the code that gives me the same error.

  <html>
    <head>
        <meta name="viewport" content width="devide-width, initial-scale=1.0">
        <title>Sistema de gestión de balizas</title>
            <link rel="stylesheet" href="style.css">
        </head>
<body>
    
        <div class="split left">
            
  <div class="left">
      
      <h1 style="text-align:center"> Sistema de gestión de balizas</h1>
      
      <hr class="solid"> 
      
     <br>


  </div>
</div>

<div class="split right">
    
  <div class="end">
    
<?php

require 'config.php';

$sql = "SELECT * FROM tbl_gps WHERE 1";
$result = $db->query($sql);
if (!$result) {
  { echo "Error: " . $sql . "<br>" . $db->error; }
}

$rows = $result -> fetch_all(MYSQLI_ASSOC);


?>
<html>
    <head>
           
          <h1 style="text-align:center"> Ubicación de las balizas</h1>
          
    </head>

<style>

/* 
 * Optional: Makes the sample page fill the window. 
 */
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: Arial;
    }

/* 
 * Always set the map height explicitly to define the size of the div element
 * that contains the map. 
 * Margin(vertical,horizontal)
 * max-width(el ancho del mapa)
 * min-height (el alto minimo del mapa)
 */

#map-layer {
	height: 60%;
	margin: 40px 40px; 
	max-width: 600px;
	min-height: 100;
    }

</style>

<body>

    	<div id="map-layer"></div>

	<script
		src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBKXiCf4p90xhFm-MugEJVk3_FMdGTrajA&callback=initMap"
		async defer></script>
		
        <script>
      
      var map;
      
      function initMap() {
        
        var mapLayer = document.getElementById("map-layer");
		var centerCoordinates = new google.maps.LatLng(48.8685,2.3045);
		var defaultOptions = { center: centerCoordinates, zoom: 10 }

		map = new google.maps.Map(mapLayer, defaultOptions);


<?php foreach($rows as $location){ ?>
        var location = new google.maps.LatLng(<?php echo $location['lat']; ?>, <?php echo $location['lng']; ?>);
        var marker = new google.maps.Marker({
            position: location,
            map: map
        });
    <?php } ?>
        
      }
        </script>
      </body>
</html>
        
        
        
    </div>
    </div>
  </div>
</div>
    </body>
</html>```

It seems like such a confusing mess. For example why are there 2x </body> and 2x </html> here? Does each end-tag have a corresponding begin-tag? Maybe mistakes like these don't matter much, but that kind of thing would make me want to go through each line in the code, one at a time, and make sure I have crossed very "t" and dotted every "i". That's how I often find bugs in my code.

Good advice. I'll take my time to carefully look at the code.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.