Help with combo boxes Database in php in two Forms!

Asked

Viewed 17 times

0

Is there any way to use two combo boxes to vary from each other type this example(Two combo boxes Where one Varies form the other using 2 Forms cant use ajax); Meu codigo

This is my database(My database) Minha database

<!DOCTYPE html>
/*
<html>
<head>
    <title>Marcar</title>
    <meta charset="utf-8"/>
</head>
<body>
<?php
if(isset($_POST['submit']))
{
    include("config.php");
    $Marca=$_POST['Marca'];
    $Modelo=$_POST['Modelo'];
    $Data=$_POST['Data'];
    $tipo=$_POST['tipo'];
      $Email=$_POST['Email'];
if(empty($Marca) ||empty($Modelo)||empty($Data)
    )
{
    echo "Deve porencher todos os valores";
}
else{
    $insert_values=$mysqli->query("insert into consulta(Email,Marca,Modelo,Tipo,Data) 
        values('$Email','$Marca','$Modelo','$tipo','$Data')");
    if($insert_values)
    {
        echo "<h3>Registo inserido</h3>";
    }
    else
    {
        die('Erro:(' .$mysqli->errno. ')'.$mysqli->error);
    }

}
}
?>
<form method="post" enctype="multipart/form-data">
Marca: <select name="Marca" id="Marca">             
   <?php
    include "config.php";
    $results=$mysqli->query("SELECT id_Marca, Marca FROM marcas");
    while($row=$results->fetch_array()){                                                 
       echo "<option value='".$row['Marca']."'>".$row['Marca']."</option>";
    }
?>

            </select> <br> <br>


Modelo: <select name="Modelo" id="Modelo">
<?php
     $results=$mysqli->query("SELECT id_Modelo,Modelo FROM modelos /*where id_Modelo like $results3*/ ");
    while($row=$results->fetch_array()){                                                 
       echo "<option value='".$row['Modelo']."'>".$row['Modelo']."</option>";
    }
    echo $results3;
?>
            </select> <br> <br>
            Tipo Prob: <input type="text" name="tipo"  id="tipo"/>
            <br>
            Data Consulta:  <input type="text" name="Data"  value="<?php echo date('Y-m-d'); ?>" id="Data" />
            <br>
             Email: <input type="text" name="Email"  id="Email"/>
            <br>
<input type="submit" value="Guardar" name="submit"/>
</form>
</body>
</html>
  • 1

    Ola Cesito, could you post the codes in the question? so it’s easier for people who will help you, to test the code.

  • Select all the source code then press the button { } to leave it formatted.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.