2
I’m making a program that receives any number and displays the next 100 even numbers, but as soon as I open the site it’s already displaying a result without even typing anything.
<!doctype html>
<html lang="pt-bt">
<head>
<title>Exercicio 3</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="css/exercicio3.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
<body>
<!--Barra de Navegação-->
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<a class="navbar-brand" href="#">Exercicios de PHP</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarText">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="index.html">Exercicio 1</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="exercicio2.php">Exercicio 2</a></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Exercicio 3</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Exercicio 4</a>
</li>
</ul>
</div>
</nav>
<div class="container">
<h3 class="page_header">Exercicio 3</h3>
<div class="row">
<div class="col-sm-6 ">
<div class="area_conteudo">
<h4 class="title_form">Faça o calculo a baixo</h4><br>
<form class="posicao" name="formulario" method="GET" action="exercicio3.php">
<label>Digite um valor inteiro</label>
<div class="form-group">
<input type="number" id="tamanho" class="form-control " name="numero" placeholder="Digite um numero">
</div>
<input type="submit" class="btn btn-primary" value=" Calcular">
</form>
<h3 class="texto_resultado">Resultado:</h3>
<!--PHP-->
<?php
$numero = $_GET['numero'];
$c = 0;
while ($c <= 100) {
if ($numero % 2 == 0) {
echo "$numero ";
}
$numero++;
$c++;
}
?>
<!--FIM-PHP-->
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>
The number is probably in the URL. Because the method you use is
$_GET
.– Andrei Coelho
Your url should look like this:
exercicio3.php?numero=12
right?– Andrei Coelho