I want to insert my choice into a mysql table I get “kleuren” from “getkleur.php” and “autos” from “index.php” If I want to insert my choice at first select “autos” it actually insert it but if I want to insert the select from “getkleur.php” it doesn’t. The intention of everything is that if I make a choice with the first select, it will show the second select and with the “submit” button it will insert the choices.
This is " index.php "
-1
I want to insert my choice into a mysql table This is " index.php " I get “kleuren” from “getkleur.php” and “autos” from “index.php” If I want to insert my choice at first select “autos” it actually insert it but if I want to insert the select from “getkleur.php” it doesn’t. The intention of everything is that if I make a choice with the first select, it will show the second select and with the “submit” button it will insert the choices.
<form method="post" action="">
<label>Auto:
<select name="auto" onChange="showKleur(this);">
<option value="">Maak een keuze</option>
<?php foreach ($results as $rs) { ?>
<option value="<?php echo $rs["autoid"]; ?>"><?php echo $rs["autonaam"]; ?></option>
<?php } ?>
</select>
</label>
</td>
</tr>
<tr>
<td align="center" height="50"><div id="output1"></div> </td>
</tr>
</table>
<button type="submit" name="submit" >Submit</button>
</form>
<?php
if(isset($_POST["submit"]))
{
//Including dbconfig file.
include 'config2.php';
include 'getkleur.php';
$subjectName=$_POST['auto'];
$subjectName1=$_POST['autoid'];
mysqli_query($conn,"INSERT INTO opslag (antwoord,antwoord1) VALUES ('$subjectName','$subjectname1')");
echo "Uw keuze is : $subjectName ";
echo "Uw keuze is : $subjectName1 ";
}
?>
</br>
</div>
</article>
</div>
</div>
<script src="jquery-1.9.0.min.js"></script>
<script>
function showKleur(sel) {
var autoid = sel.options[sel.selectedIndex].value;
$("#output1").html("");
if (autoid.length > 0) {
$.ajax({
type: "POST",
url: "getkleur.php",
data: "autoid=" + autoid,
cache: false,
beforeSend: function() {
$('#output1').html('<img src="loader.gif" alt="" width="24" height="24">');
},
success: function(html) {
$("#output1").html(html);
}
});
}
}
</script>
And this is my " getkleur.php " for the second select
<?php
require("configure.php");
$autoid = ($_REQUEST["autoid"] <> "") ? trim($_REQUEST["autoid"]) : "";
if ($autoid <> "") {
$sql = "SELECT * FROM kleuren WHERE autoid = :cid ORDER BY kleurnaam ASC";
try {
$stmt = $DB->prepare($sql);
$stmt->bindValue(":cid", trim($autoid));
$stmt->execute();
$results = $stmt->fetchAll();
} catch (Exception $ex) {
echo($ex->getMessage());
}
if (count($results) > 0) {
?>
<label>Kleur:
<form method="POST">
<select name="state" id="state">
<?php foreach ($results as $rs) { ?>
<option value="<?php echo $rs["kleurid"]; ?>"><?php echo $rs["kleurnaam"]; ?></option>
<?php } ?>
</select>
</label>
</form>
<?php
}
}
?>