Javascript to php the same file - javascript

I have a problem. I need to get the value from a select tag then use it in php for my sql. Here is my code
<div class="form-group">
<label> ROOMS </label>
<?php
echo "<select value= 'TRoom1' id ='TRoom1' class='form control'>";
echo "<option>Select Room Type</option>";
while ($row1 = mysql_fetch_array($result2))
{
echo "<option>" . $row1['Room_type'] . "</option>";
}
echo "</select>";
?>
this is for the sql command
<div class="modal-body">
<div class="container">
<?php
$selectedValue = $_POST['TRoom1'];
$sql = "SELECT RoomNumber FROM rooms Where Room_type = '$selectedValue' ";
$result = mysql_query($sql);
echo "<select value= 'RoomNo' id ='RoomID' class='form-control'>";
echo "<option>Select Room Number</option>";
while ($row = mysql_fetch_array($result))
{
echo "<option>" . $row['RoomNumber'] . "</option>";
}
echo "</select>";
?>
TIA! :))
THis is the code ofor room type with its corresponding room number
<div class="form-group">
<label for="exampleInputEmail1"> ROOMS </label>
<?php
echo "<select value= 'TRoom1' name ='TRoom1' id ='TRoom1' class='form-control'>";
echo "<option>Select Room Type</option>";
while ($row1 = mysql_fetch_array($result2))
{
echo "<option>" . $row1['Room_type'] . "</option>";
}
echo "</select>";
?>
</div>
<div class="form-group">
<?php
$select_value=$_POST['selectedValue'];
$sql = "SELECT RoomNumber FROM rooms Where Room_type = '$select_value' ";
$result = mysql_query($sql);
echo "<select value= 'RoomNo' id ='RoomID' class='form-control'>";
echo "<option>Select Room Number</option>";
while ($row = mysql_fetch_array($result))
{
echo "<option>" . $row['RoomNumber'] . "</option>";
}
echo "</select>";
?>
</div>

you need to use name attribute for your select tag if u want to fetch the value in the php part and in the option u have to pass the value attibute.that value u will get in the php part.
<html>
<head></head>
<body>
<form action="a.php" method="post">
<select name="selectname" id="someid" >
<?php
while ($row1 = mysql_fetch_array($result2))
{
?>
<option value="<?php echo $varible ?>"> <?php echo $row1['Room_type']; ?></option>
<?php } ?>
</select>
<input type="submit" value="submit">
</form>
</body>
</html>
for php part:u can fetch value like this:
filename=a.php
<?php
$select_value=$_REQUEST['selectname'];
$sql1 = "SELECT RoomNumber FROM rooms Where Room_type = '$select_Value' ";
$sql=mysql_result(mysql_query($sql1),0);
?>

Please google your doubts before posting here. There are plenty of example available. mysql_query is deprecated use mysqli_ function
<div class="form-group">
<label> ROOMS </label>
<?php
echo "<select id ='TRoom1' name ='TRoom1' class='form control'>";
echo "<option>Select Room Type</option>";
while ($row1 = mysql_fetch_array($result2))
{
echo "<option value=".$row1['Room_type'].">" . $row1['Room_type'] . "</option>";
}
echo "</select>";
?>
If you are submitting your form as post you would get values as
$sql = "SELECT Room_type, Rate, RoomNumber FROM rooms Where Room_type ='".$_POST['TRoom1']."' ";

Try like
var Sel_val = document.getElementById('TRoom1').value;
Sel_val will be the selected value of that Dropdown.Better you use ajax in your case.If it is on the same page then you use Form submit method.
For the ajax first you need the target url and the value which you want to send..So try like
$.ajax({
url : Url of the page at which the sql command will be there,
type : 'POST',
data : { Sel_val : Sel_val }
});
Then at your target file get the Sel_val via POST method.

I think you used the self action and try this below code
if($_POST){
$selectedValue = $_POST['TRoom1'];
$sql = "SELECT RoomNumber FROM rooms Where Room_type = '$selectedValue' ";
$result = mysql_query($sql);
echo "<select value= 'RoomNo' id ='RoomID' class='form-control'>";
echo "<option>Select Room Number</option>";
while ($row = mysql_fetch_array($result))
{
echo "<option>" . $row['RoomNumber'] . "</option>";
}
echo "</select>";
}

Related

PHP set dropdown value after page refresh

I'm having trouble setting the value of the dropdown after the form input refreshes the page. I can get the value but no matter what I try I'm unable to set the dropdown after the page refreshes. I've tried a number of different ideas I've found online too. I've tried both JavaScript and PHP solutions and all I can do is get the value but not set it. This is the code I have so far, which returns the drop down ID, I just need to know how to use it. I appreciate any help, thanks!
<?php
$pdo = new PDO('mysql:host=localhost; dbname=db', 'root', 'password')'
$sql = "SELECT divid, division FROM divisions ORDER BY division ASC";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$divs = $stmt->fetchAll();
?>
<form method="post">
<select id="divi" name="divisions">
<?php foreach($divs as $div): ?>
<option value="<?= $div['divid'];?>"><?= $div['division']; ?></option>
<?php endforeach; ?>
</select>
<input type="submit" name="submit" value="Submit">
</form>
<?php
if(isset($_POST['submit'])){
if(!empty($_POST['divisions'])){
$selected = $_POST['divisions'];
echo 'Selected: " . $selected;
} else {
echo 'Select division.';
}
}
?>
It's not very clear to me what you really want, however it looks like you want to select default:
<select id="divi" name="divisions">
<?php foreach($divs as $div): ?>
<option <?php echo ("mycondition ex: 'id == 1'") ? "selected" : NULL ?> value="<?= $div['divid'];?>"><?= $div['division']; ?></option>
<?php endforeach; ?>
</select>
You are simply missing any code that sets 'selected="selected"' in the HTML for the select field.
Also, your code is very hard to read so I've cleaned up the loop a little bit.
<form method="post">
<?php
echo '<select id="divid" name="divid">';
foreach ($divs as $div) {
$selected = '';
if (isset ($_POST['divid']) && ($_POST['divid'] == $div['divid'])) {
$selected = 'selected="selected"';
}
echo '<option value="' . $div['divid'] . '" ' . $selected . '>' . $div['division'] . '</option>';
}
echo '</select>';

autosubmit drop down value into database

i'm trying to auto submit the value of drop down menu using onchange=this.form.submit() into database but i couldn't make it work. can anyone please help me. any suggestions will be highly appreciated.
here is the code:
<?
require_once ('database.php');
?>
<form action="" method=post>
<select name="assignee" onchange="this.form.submit()">
<option value="0">Unassigned</option>
<?
$find_selected = mysql_query("select assign_to from orders where id = $id");
$asignee =mysql_fetch_row($find_selected);
$list=mysql_query("SELECT id, full_name from user where username <> 'root' and nature = 3");
while($row_list=mysql_fetch_assoc($list)){
?>
<option value="<? echo $row_list['id']; ?>"<? if($row_list['id']== $asignee['0']){ echo "selected"; } ?>><? echo $row_list['full_name'] ?></option>
<?
}
mysql_free_result($list);
mysql_free_result($find_selected);
?>
</select>
</form>
<?php
if(isset($_POST['submit'])){
$sql = "UPDATE `orders` SET `assign_to` = '{$_POST['assignee']}' WHERE `id` = '$id' ";
mysql_query($sql) or die(mysql_error());
}
?>
<?php
if(isset($_POST['assignee'])){
$sql = "UPDATE `orders` SET `assign_to` = '{$_POST['assignee']}' WHERE id=$id";
mysql_query($sql);
}
?>
You just defined your query but didn't executed it

Place a list inside an session and display each session

Im trying to create a shopping cart style website. I'm able to display the products through setting the products as a class and passing that through to my shopping cart page. However, I need to save the list of products into a session so I can add and or clear each item added to the cart.
Products.php
<?php
require_once 'class_product.php';
$product = new product();
$product_id =(int)$_GET['product_id']; //get id from home page
$username = "";
$password = "";
$hostname = "";//blanked this out for public use
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
//select a database to work with
$selected = mysql_select_db("poti",$dbhandle)
or die("Could not select examples");
//execute the SQL query and return records
$result = mysql_query("SELECT * FROM products where product_id=$product_id");
echo '<form name="form1" method="post" action="cart.php" target="bottom_right">';
echo '<table class="Grocery-table">';
while($row = mysql_fetch_array($result))
{
$product->setProductId($row['product_id']);
$product->setProductName($row['product_name']);
$product->setStock($row['in_stock']);
$product->setUnitPrice($row['unit_price']);
$product->setUnitQuantity($row['unit_quantity']);
}
$_SESSION['product'] = serialize($product);
echo "<tr><td><b>Product ID</b></td>";
echo "<td>";
echo $product->getProductId();
echo "</td></tr>";
echo "<tr><td><b>Product Name</b></td>";
echo "<td>";
echo $product->getProductName();
echo "</td></tr>";
echo "<tr><td><b>Unit Price</b></td>";
echo "<td>";
echo $product->getUnitPrice();
echo "</td></tr>";
echo "<tr><td><b>Unit Quantity</b></td>";
echo "<td>";
echo $product->getUnitQuantity();
echo "</td></tr>";
echo "<tr><td><b>In Stock</b></td>";
echo "<td>";
echo $product->getStock();
echo "</td></tr>";
echo '<tr><td><b>Add</b></td><td><Input type="number" min="0" id="add_value" name="cart"></input>
<Input type="hidden" id="stock_value" name="stock_value" value ='.trim($product->getStock()).'></input></td></tr>';
echo '<tr><td></td><td><input type="submit" value="Submit" onclick="return numCheck()"></td></tr>';
echo "</table>";
echo "</form>";
?>
cart.php
<?php
session_start();
?>
<html>
<style type="text/css">
</style>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Grocery Store</title>
</head>
<body>
<h2>Cart</h2>
<?php
require_once 'class_product.php';
$product = unserialize($_SESSION['product']);
//this allows me to see the information when i click submit
echo $product->getProductName();
echo $product->getProductId();
echo $product->getStock();
echo $product->getUnitPrice();
echo $_POST['cart'];
?>
</body>
</html>
How do i place the following $product->getProductName() etc into a Session that enables me to display all the products i've added to my cart.
Try this,
session_start();
$_SESSION['ProductName'] = $product->getProductName();
$_SESSION['ProductId'] = $product->getProductId();
$_SESSION['Stock'] = $product->getStock();
$_SESSION['UnitPrice'] = $product->getUnitPrice();
For multiple products, you may have to use an array of session.
<?php
session_start();
if(!isSet($_SESSION['cart_items']))
{
$_SESSION['cart_items'] = array();
}
$items =$product->getProductName()."|".$product->getProductId()."|".$product-
>getStock()."|".$product->getUnitPrice();
array_push($_SESSION['cart_items'],$items);
echo $_SESSION['cart_items'][0]; //First Product
echo "<br>";
echo $_SESSION['cart_items'][1]; //Second Product
?>

Inserting data into two tables resulting in "Array to string conversion"

I'm trying to create a form for my system, user could add the numbers of input fields, the input fields are mostly drop down box with the options coming from tables in the database. The forms would insert the data into two different database. But it shows error of "Array to string conversion" Right now the data only inserted into the first table. Here's what I'd done so far
My form's code:
<form method="post" name="maklumat_akaun" action="proses_daftar_akaun.php">
<label for="NoAkaun">No. Akaun</label>
<input type="text" id="NoAkaun" name="NoAkaun" class="required input_field" required/>
<div class="cleaner_h10"></div>
<label for="KodDaerah">Daerah</label>
<?php
include('dbase.php');$sql = "SELECT KodDaerah, NamaDaerah FROM koddaerah";
$result = mysql_query($sql);
echo "<select name='KodDaerah' id='KodDaerah' class='input_field' required /><option></option>";
while($kod = mysql_fetch_array($result)){
echo "<option value=".$kod['KodDaerah'].">" .$kod['NamaDaerah']."</OPTION>";
}
echo "</select>";
?>
<div class="cleaner_h10"></div>
<label for="KodBahagian">Bahagian</label>
<?php
$sql = "SELECT KodBahagian, NamaBahagian FROM kodbahagian";
$result = mysql_query($sql);
echo "<select name='KodBahagian' id='KodBahagian' class='input_field' required /><option></option>";
while($kod = mysql_fetch_array($result)){
echo "<option value=".$kod['KodBahagian'].">" .$kod['NamaBahagian']."</OPTION>";
}
echo "</select>";
?>
<div class="cleaner_h10"></div>
<label for="KodKategori">Kategori Akaun</label>
<?php
$sql = "SELECT KodKategori, NamaKategori , SubKategori FROM kodkategori";
$result = mysql_query($sql);
echo "<select name='KodKategori' id='KodKategori' class='input_field' required /><option></option>";
while($kod = mysql_fetch_array($result)){
echo "<option value=".$kod['KodKategori'].">" .$kod['NamaKategori']." (".$kod['SubKategori'].")</OPTION>";
}
echo "</select>";
?>
<div class="cleaner_h10"></div>
<label for="Tarif">Tarif</label>
<input type="text" maxlength="4" size="4" id="Tarif" name="Tarif" class="required year_field" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')">
<div class="cleaner_h10"></div>
<!-----------------------------------------------------------//-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
var max_fields = 25; //maximum input boxes allowed
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var x = 1; //initial text box count
$(add_button).click(function(e){ //on add input button click
e.preventDefault();
if(x < max_fields){ //max input box allowed
x++; //text box increment
$(wrapper).append('<div>'+
'<td> <?php
$sql = "SELECT KodLokasi, NamaLokasi FROM kodlokasi";
$result = mysql_query($sql);
echo "<select name=\'KodLokasi[]\' id=\'KodLokasi[]\' class=\'input_field\' required ><option></option>";
while($kod = mysql_fetch_array($result)){
echo "<option value=".$kod['KodLokasi'].">" .$kod['NamaLokasi']. "</OPTION>";
}
echo "</select>";
?> </td> </tr>'+
'<tr> <td> <?php
$sql = "SELECT KodJenisAkaun, NamaJenisAkaun FROM kodjenisakaun";
$result = mysql_query($sql);
echo "<select name=\'KodJenisAkaun[]\' id=\'KodJenisAkaun[]\' class=\'input_field\' required ><option></option>";
while($kod = mysql_fetch_array($result)){
echo "<option value=".$kod['KodJenisAkaun'].">" .$kod['NamaJenisAkaun']. "</OPTION>";
}
echo "</select>";
?> </td>'+
'<td> <input type="text" name="NoTelefon[]" id="NoTelefon[]" value="0" class="required input_field"> </td>' +
'Batal</tr></div>'); //add input box
}
});
$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
e.preventDefault(); $(this).parent('div').remove(); x--;
});
});
</script>
<fieldset>
<div class="input_fields_wrap">
<h3 class="add_field_button">Add More Fields</h3>
<table>
<tr>
<td> <label for="KodLokasi">Lokasi</label> </td> <td> <label for="KodJenisAkaun">Jenis Akaun</label> </td> <td> <label>No.Telefon:</label> </td>
</tr>
<tr>
<td> <?php
$sql = "SELECT KodLokasi, NamaLokasi FROM kodlokasi";
$result = mysql_query($sql);
echo "<select name='KodLokasi[]' id='KodLokasi' class='input_field' required /><option></option>";
while($kod = mysql_fetch_array($result)){
echo "<option value=".$kod['KodLokasi'].">" .$kod['NamaLokasi']."</OPTION>";
}
echo "</select>";
?>
</td>
<td> <?php
$sql = "SELECT KodJenisAkaun, NamaJenisAkaun FROM kodjenisakaun";
$result = mysql_query($sql);
echo "<select name='KodJenisAkaun[]' id='KodJenisAkaun' class='input_field' required /><option></option>";
while($kod = mysql_fetch_array($result)){
echo "<option value=".$kod['KodJenisAkaun'].">" .$kod['NamaJenisAkaun']."</OPTION>";
}
echo "</select>";
?>
</td>
<td> <input type="text" name="no_telefon[]" value="0" class="required input_field" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')"> </td>
</tr>
</table>
</div>
</fieldset>
<!-----------------------------------------------------------//-->
<div class="cleaner_h10"></div>
<div class="cleaner_h10"></div>
<input type="submit" value="Daftar" id="submit" name="register-submit" class="submit_btn" />
<input type="reset" value="Batal" id="reset" name="reset" class="submit_btn" />
</table>
</form>
While this is my code for the inserting process.
<?php
require("dbase.php");
if ($_POST) {
$NoAkaun = isset($_POST['NoAkaun']) ? $_POST['NoAkaun'] : '';
$KodBahagian = isset($_POST['KodBahagian']) ? $_POST['KodBahagian'] : '';
$Tarif = ISSET($_POST['Tarif']) ? $_POST['Tarif'] : '';
$KodDaerah = isset($_POST['KodDaerah']) ? $_POST['KodDaerah'] : '';
$KodKategori = isset($_POST['KodKategori']) ? $_POST['KodKategori'] : '';
$NoTelefon = isset($_POST['NoTelefon']) ? $_POST['NoTelefon'] : '';
$KodLokasi = isset($_POST['KodLokasi']) ? $_POST['KodLokasi'] : '';
$KodJenisAkaun = isset($_POST['KodJenisAkaun']) ? $_POST['KodJenisAkaun'] : '';
$akaun_idAkaun = isset($_POST['akaun_idAkaun']) ? $_POST['akaun_idAkaun'] : '';
$sql = mysql_query("INSERT INTO maklumatakaun VALUES ('', '$NoAkaun' , '$KodBahagian' , '$KodDaerah' , '$KodKategori' , '$Tarif' )");
$akaun_idAkaun = mysql_insert_id();
foreach ($NoTelefon AS $i => $telefon) {
$sql = mysql_query("INSERT INTO detailakaun VALUES ('', '$KodLokasi[$i]', '$KodJenisAkaun' , '$telefon' , '$akaun_idAkaun' )");
}
echo "<script type='text/javascript'> alert('AKAUN BERJAYA DIDAFTARKAN')</script> ";
echo "<script type='text/javascript'>window.location='pilih_kategori_daftar.php'</script>";
}
?>
Can anyone help me figure this out?
The error "Array to string conversion" means you are using an array as a string somewhere in your code. That error message is usually followed by a filename and line number which should help you narrow down your search. One helpful way to see what is contained within a variable is to use the following:
echo '<pre>'; print_r($stuff); die();
If the error is happening on a line inside of a while loop you should put the echo '' before the while and the die(); after so that you can see all instances of the problem within the loop.
I found your problem on this statement
$sql = mysql_query("INSERT INTO detailakaun VALUES ('', '$KodLokasi[$i]', '$KodJenisAkaun' , '$telefon' , '$akaun_idAkaun' )");
$KodJenisAkaun is an array and you use it as a string

How can I get a value from a select box on the same page

I'm trying to use PHP and Javascript to make a category selector box.
I've set it up so that the Javascript will show the steps in order of being selected, and hide after being deselected.
However, I can't figure out how to take the selected options "id" or "value" and pass it to the next line. (once the chosen id or value is passed on, the next list can load)
Here is my code, Thanks in advance for looking. And please, if I'm doing something wrong or not the right way. Let me know and/or show me the right way to do it.
<?php
include($_SERVER["DOCUMENT_ROOT"] . "/inc/header.php");
include($_SERVER["DOCUMENT_ROOT"] . "/inc/search.php");
?>
<div class="content">
<form>
<select name="categorys" class="newcatediv" id="step1" size="3" onchange="mine(this.value)">
<?php
$result_c = mysqli_query($con,"SELECT * FROM categories ORDER BY category_name ASC");
while($row = mysqli_fetch_array($result_c))
{
echo '<option class="mso" id="'. $row['category_nameid'] .'"value="';
echo $row['category_nameid'] .'">' . $row['category_name'] . '</option>';
}
?>
</select>
<select name="sections" class="newcatediv" id="step2" size="3" onchange="mine2(this.value)">
<?php
$var_c = ????
$result_s = mysqli_query($con,"SELECT * FROM sections WHERE category_nameid='$var_c' ORDER BY section_name ASC");
while($row = mysqli_fetch_array($result_s))
{
echo '<option class="mso" id="'. $row['section_nameid'] .'"value="';
echo $row['section_nameid'] .'">' . $row['section_name'] . '</option>';
}
?>
</select>
<select name="subsections" class="newcatediv" id="step3" size="3">
<?php
$var_s = ????
$result_ss = mysqli_query($con,"SELECT * FROM subsections WHERE section_nameid='$var_s' ORDER BY subsection_name ASC");
while($row = mysqli_fetch_array($result_ss))
{
echo '<option class="mso" id="'. $row['subsection_nameid'] .'"value="';
echo $row['subsection_nameid'] .'">' . $row['subsection_name'] . '</option>';
}
?>
</select>
</form>
</div>
<?php
include($_SERVER["DOCUMENT_ROOT"] . "/inc/footer.php");
?>
By default, the first option in a <select> is selected, so this would work:
<select name="categorys" class="newcatediv" id="step1" size="3" onchange="mine(this.value)">
<?php
$result_c = mysqli_query($con,"SELECT * FROM categories ORDER BY category_name ASC");
$var_c = null;
while($row = mysqli_fetch_array($result_c))
{
if($var_c == null) $var_c = $row['category_nameid'];
echo '<option class="mso" id="'. $row['category_nameid'] .'"value="';
echo $row['category_nameid'] .'">' . $row['category_name'] . '</option>';
}
?>
</select>
<select name="sections" class="newcatediv" id="step2" size="3" onchange="mine2(this.value)">
<?php
$result_s = mysqli_query($con,"SELECT * FROM sections WHERE category_nameid='$var_c' ORDER BY section_name ASC");
$var_s = null;
while($row = mysqli_fetch_array($result_s))
{
if($var_s == null) $var_s = $row['section_nameid'];
echo '<option class="mso" id="'. $row['section_nameid'] .'"value="';
echo $row['section_nameid'] .'">' . $row['section_name'] . '</option>';
}
?>
</select>
<select name="subsections" class="newcatediv" id="step3" size="3">
<?php
$result_ss = mysqli_query($con,"SELECT * FROM subsections WHERE section_nameid='$var_s' ORDER BY subsection_name ASC");
while($row = mysqli_fetch_array($result_ss))
{
echo '<option class="mso" id="'. $row['subsection_nameid'] .'"value="';
echo $row['subsection_nameid'] .'">' . $row['subsection_name'] . '</option>';
}
?>
</select>
Cheers
Hi :) You Can't Process that at the same page using Php. But you can do that with this jquery including 3 pages.
First Page:
$(document).ready(function(){
$("#step1").change(function(){
var id=$("#step1").val();
alert(id); //shouts the value of the selected step1
$.post("select_step2.php", {id:id}, function(data){
$("#step2").empty();
$("#step2").append(data);
$("#step2").change(function(){
var id2=$("#step2").val();
alert(id2); //shouts the value of the selected step2
$.post("select_step3.php", {id:id2}, function(data){
$("#step3").empty();
$("#step3").append(data);
});
});
});
});
});
The above code is for jquery where you can call each data's that depends on each step.
<?php
include($_SERVER["DOCUMENT_ROOT"] . "/inc/header.php");
include($_SERVER["DOCUMENT_ROOT"] . "/inc/search.php");
?>
<form>
First Step: <select name="categorys" class="newcatediv" id="step1" size="3">
<?php
$result_c = mysqli_query($con,"SELECT * FROM categories ORDER BY category_name ASC");
while($row = mysqli_fetch_array($result_c))
{
echo '<option class="mso" id="'. $row['category_nameid'] .'"value="';
echo $row['category_nameid'] .'">' . $row['category_name'] . '</option>';
}
?>
</select>
Second Step: <select name="sections" class="newcatediv" id="step2" size="3"></select>
Third Step: <select name="subsections" class="newcatediv" id="step3" size="3"></select>
Code for you select_step2.php:
<?php
//Please include the connection to your database here :)
$var_c = trim($_POST['id']);
$section = "";
$result_s = mysqli_query($con,"SELECT * FROM sections WHERE category_nameid='$var_c' ORDER BY section_name ASC");
while($row = mysqli_fetch_array($result_s))
{
$section.="<option value='$row[section_nameid]'>$row[section_name]</option>";
}
echo $section;
?>
Code for your select_step3.php:
<?php
//database connection here
$var_s = trim($_POST['id']);
$subsection= "";
$result_ss = mysqli_query($con,"SELECT * FROM subsections WHERE section_nameid='$var_s' ORDER BY subsection_name ASC");
while($row = mysqli_fetch_array($result_ss))
{
$subsection.="<option value='$row[subsection_nameid]'>$row[subsection_name]</option>";
}
echo $subsection;
?>

Categories