Help with this php error query between

0
<form method="_POST">
    <p>Busqueda</p>
    <p>
        <input type="text" name="busca" id="busca">
    </p>
    <p>
        <input type="text" name="busca1" id="busca1">
    </p>
    <label>
        <input type="submit" name="submit" value"buscar">
    </label>
</form>
<?php
    $busca="";
    $busca1="";
    $busca=$_POST['busca'];
    $busca1=$_POST['busca1'];
    $conexion= mysqli_connect('localhost','root','');
    mysqli_select_db($conexion,'premios_bd');
    if($busca!="" && $busca1!=""){
        $busqueda=mysql_query("SELECT * FROM ganador Where N_acta BETWEEN '$busca' AND '$busca1'");
        while($f=mysql_fech_arrar($busqueda)){
            echo $f['Item'].'&nbsp;&nbsp;'.$f['Nombres']."<br>";
        }
    }
?>

I have this code to make a query to the bd mysql with a query between but I get the following error when opening the web:

  

Notice: Undefined index: search in C: \ xampp \ htdocs \ tres.php on line 16

     

Notice: Undefined index: search1 in C: \ xampp \ htdocs \ tres.php on line 17

    
asked by ronald 19.04.2018 в 19:35
source

2 answers

1

Your problem is that when you load the page you are trying to collect by post the values, which do not really arrive. The correct way is to detect when the user sends that form, for that we use the isset function.

<form method="POST">
<p> Busqueda</p>
<p>
    <input type="text" name="busca" id="busca">
</p>
<p>
    <input type="text" name="busca1" id="busca1">
</p>
<label>
    <input type="submit" name="submit" value"buscar">
</label>
</form>

PHP code.

<?php
    if(isset($_POST['submit'])){
        $busca="";

        $busca1="";

        $busca=$_POST['busca'];

        $busca1=$_POST['busca1'];


        $conexion= mysqli_connect('localhost','root','');

        mysqli_select_db($conexion,'premios_bd');

        if($busca!="" && $busca1!=""){

            $busqueda=mysql_query("SELECT * FROM ganador Where N_acta BETWEEN '$busca' AND '$busca1'");

            while($f=mysql_fech_arrar($busqueda)){
                echo $f['Item'].'&nbsp;&nbsp;'.$f['Nombres']."<br>";
            }

        }
    }
?>
    
answered by 19.04.2018 / 19:47
source
0

You should check first if the posts are set, the first time you load the page, the 'search' and 'search1' posts do not come.

if (isset($_POST['busca']) && isset($_POST['busca1']){

Also in the while the fetch is misspelled

while($f=mysql_fech_arrar($busqueda)){

change to

while($f=mysql_fetch_array($busqueda)){
    
answered by 19.04.2018 в 19:49