How to make an input yield a specific result

0

Good I am making a table and it throws the results to me in table form but I occupy that it throws to me now the result that I enter in the input if I put for example 5x14 that throws me only that and I do not throw all the tables I do not know if removing the for can but I get an error this is my code:

 <!DOCTYPE html>
<meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <link rel="stylesheet" href="tablass.css"
<html lang="es">
<head>

<title> </title>

</head>
<body>

<?php
$b=5;
$multi;
echo"<table border=1 cellspacing=0 width=200";
echo "<tr><th colspan=5> Tabla del $b </th></tr>";

 for($i=10; $i<=15; $i++) {   

    $multi= $i * $b;
echo "<tr><td align=center>$b</td>
             <td align=center>x</td>
             <td align=center>$i</td>
             <td align=center>=</td>
             <td align=center> ". $b*$i . "</td>
         </tr>";
 }
 echo "</table> <br/>";

 ?>


    <!DOCTYPE html>
<meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <link rel="stylesheet" href="tablass.css"
<html lang="es">
<head>

<title> </title>

</head>
<body>
<h1>TABLA DEL 5 V2</h1>
<form action="tablaav2.php" method="post">
<h1>DAME 5</h1>:
<input type="text" name="valor1"><br>
<h1>DAME RANGO DEL 10 AL 15</h1>:
<input type="text" name="valor2"><br>
<br>
<input type="submit" value="Aceptar">

</form>
</body>

se me ocurrio poner esto pero da error:

    if($i==10){
         ´echo .($b * 10);

     }
     if($i==11){ 
     echo .($b * 11);
     }
    
asked by wdwd 10.04.2018 в 18:12
source

2 answers

1

If I understood correctly and what you want is by means of a form meter 2 numbers and that you return the result of multiplying both, try as follows

  

index.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <form action="opera.php" method="POST">
                <input type="text" name="numero1" >
                <input type="text" name="numero2">
                <input type="submit" value="ope">
    </form>
</body>
</html>
  

opera.php

<?php

$uno = $_POST['numero1'];
$dos = $_POST['numero2'];

echo $uno * $dos;
  

Where, as you can see, I use a form, through the POST method   I send the variables, remember for PHP to read the variables should   have a name, same name that I occupy in the second file opera.php

    
answered by 10.04.2018 / 18:27
source
2

When embedding PHP in HTML you must use and respect the tags of each language.

Your exercise is going very well only when using the . point is because you need to concatenate more than two values, strings, constants, etc.

This would be the correct syntax for your code segment in PHP

<?php
if($i==10)
{
    echo ($b * 10);
}
if($i==11)
{ 
    echo ($b * 11);
}
?>
    
answered by 10.04.2018 в 18:28