Below is code that I am using, when i submit the survey, arrrive and mode work but not trans/checkboxes, data comes back displayed as 'on' in table (survey) database (wdtlabwork), also the field is trans, same with the other two being mode n arrive in the database, all fields were type VARCHAR. Apologies if formatting is bad i am new to site.
HTML
<section id="content">
<form action="connect.php" method="post">
<div class="col-6 col-s-9">
<h3>Available Transportation?</h3>
<input id="trans1" type="checkbox" name="trans[]"><label for ="trans1">Car</label>
<input id="trans2" type="checkbox" name="trans[]"><label for ="trans2">Train</label>
<input id="trans3" type="checkbox" name="trans[]"><label for ="trans3">Bus</label>
<h4>How do you intend to arrive at the Hostel?</h4>
<input id="arrive1" type="radio" value="car" name="arrive"><label for="arrive1">Car</label>
<input id="arrive2" type="radio" value="train" name="arrive"><label for="arrive2">Train</label>
<input id="arrive3" type="radio" value="bus" name="arrive"><label for="arrive3">Bus</label>
<h5>Preferred mode of transport?</h5>
<select name="mode">
<option selected hidden value="">Select Option</option>
<option value="car">Car</option>
<option value="train">Train</option>
<option value="bus">Bus</option>
</select><input type="submit" class="btn btn=primary"></div></section>
PHP
<?php
$arrive = $_POST['arrive'];
$trans = $_POST['trans'];
$mode = $_POST['mode'];
$conn = new mysqli('localhost', 'root','','wdtlabwork');
if ($conn->connect_error){
die('Connection Failed : '.$conn-> connect_error);
}else{
$stmt = $conn->prepare("insert into survey(trans, arrive, mode)
values(?, ?, ?)");
$stmt->bind_param("sss",$trans, $arrive, $mode);
$stmt->execute();
echo "registration successfully...";
$stmt->close();
$conn->close();
}
?>
Aucun commentaire:
Enregistrer un commentaire