Code: Select all
<?php
require('layout.php');
$servername = "";
$username = "";
$password = "";
$dbname = "";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo '<form action="" method="post">';
$q=$conn->query("SELECT DISTINCT id,categorie FROM categorii ORDER BY categorie");
foreach($q as $cat){
echo '<a href="'.$cat['categorie'].'">'.$cat['categorie'].'</a>';
echo '<ul class="sub-menu">';
$linkq=$conn->query("SELECT intrebare,tip1,tip2,tip3 FROM intrebari WHERE categorie='" . $cat['id'] . "'");
foreach($linkq as $link){
echo '<input type="checkbox" name="tv[]" value="'.$link['intrebare'].'"> '.$link['intrebare'].' <br>
<select name="'.$link['intrebare'].'">
<option value="'.$link['tip1'].'">'.$link['tip1'].'</option>
<option value="'.$link['tip2'].'">'.$link['tip2'].'</option>
<option value="'.$link['tip3'].'">'.$link['tip3'].'</option>
</select><br>';
}
echo '</ul></li>';
}
echo ' <input type="submit" name="Submit" value="Submit">
</form>';
?>
<?php
$sDbHost = '';
$sDbName = '';
$sDbUser = '';
$sDbPwd = '';
$dbConn = mysql_connect ($sDbHost, $sDbUser, $sDbPwd) or die ('MySQL connect failed. ' . mysql_error());
mysql_select_db($sDbName,$dbConn) or die('Cannot select database. ' . mysql_error());
session_start();
$checkbox1 = $_POST['tv'];
if($_POST["Submit"]=="Submit")
{
for ($i=0; $i<sizeof($checkbox1);$i++) {
$query2="INSERT INTO chestionar (intrebari) VALUES ('".$checkbox1[$i]."')";
mysql_query($query2) or die ('Error updating database');
echo "Record is inserted.";
}
}
?>
I create a select option for all checkbox generated from database.How can i get value from select option and insert in database?